Module: Her::Model::Parse::ClassMethods

Defined in:
lib/her_extension/model/parse.rb

Instance Method Summary collapse

Instance Method Details

#to_params(attributes, changes = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/her_extension/model/parse.rb', line 16

def to_params(attributes, changes = nil)
  filtered_attributes = attributes.dup.symbolize_keys
  filtered_attributes.merge!(embeded_params(attributes) || {})
  if her_api && her_api.options[:send_only_modified_attributes] && !changes.nil?
    filtered_attributes = changes.symbolize_keys.keys.inject({}) do |hash, attribute|
      hash[attribute] = filtered_attributes[attribute]
      hash
    end
  end

  if include_root_in_json?
    if json_api_format?
      { included_root_element => [filtered_attributes] }
    else
      { included_root_element => filtered_attributes }
    end
  else
    filtered_attributes
  end
end