Skip to content

Commit

Permalink
Refactored code to fix codeclimate issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
leio10 authored and deivid-rodriguez committed Jun 2, 2018
1 parent b7d8658 commit 3fe5ac0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/rectify/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class Form

def self.from_params(params, additional_params = {})
params_hash = hash_from(params)

mimicked_params = params_hash[mimicked_model_name]
mimicked_params = {} unless mimicked_params.is_a?(Hash)
mimicked_params = ensure_hash(params_hash[mimicked_model_name])

attributes_hash = params_hash
.merge(mimicked_params)
Expand Down Expand Up @@ -56,6 +54,14 @@ def self.hash_from(params)
params.with_indifferent_access
end

def self.ensure_hash(object)
if object.is_a?(Hash)
object
else
{}
end
end

def persisted?
id.present? && id.to_i > 0
end
Expand Down

0 comments on commit 3fe5ac0

Please sign in to comment.