vendor/bundle/ruby/2.3.0/gems/freelancer-0.1.1/lib/freelancer/support/json_mapper.rb
# Populate the fields of the model by mapping the JSON data structure
# specified against the model attributes.
Populate the fields of the model by mapping the JSON data structure
specified against the model attributes.
Populate the fields of the model by mapping the JSON data structure specified against the model attributes .
def from_json(json)
        json.each_pair do |key, value|
          if value.is_a?(Hash) && mapped_as_hash?(key)
            value.each_pair do |nested_key, nested_value|
              map_key = mapped_from({ key => nested_key })
              raise ArgumentError.new("Unable to map key #{{ key => nested_key }.inspect} to model attribute") if map_key.nil?
              model[map_key] = nested_value
            end
          else
            map_key = mapped_from(key)
            raise ArgumentError.new("Unable to map key #{key} to model attribute") if map_key.nil?
            model[map_key] = value
          end
        end
        model
      end
def from_json ( json ) json . each_pair do | key , value | if value . is_a? ( Hash ) && mapped_as_hash? ( key ) value . each_pair do | nested_key , nested_value | map_key = mapped_from ( { key => nested_key } ) raise ArgumentError . new ( "Unable to map key #{{ key => nested_key }.inspect} to model attribute" ) if map_key . nil? model [ map_key ] = nested_value end else map_key = mapped_from ( key ) raise ArgumentError . new ( "Unable to map key #{key} to model attribute" ) if map_key . nil? model [ map_key ] = value end end model end
Populate the fields of the model by mapping the JSON data structure
specified against the model attributes.
Populate the fields of the model by mapping the JSON data structure specified against the model attributes .
# If our value is a hash and it's mapped by the mapper, # do a special hash lookup on the map target # for each of the key+nested key combinations
json
<not_specific>