lib/gorillib/model/base.rb
#
# Accept the given attributes, converting each value to the appropriate
# type, constructing included models and collections, and other triggers as
# defined.
#
# Use `#receive!` to accept 'dirty' data -- from JSON, from a nested hash,
# or some such. Use `#update_attributes` if your data is already type safe.
#
# @param [{Symbol => Object}] hsh The values to receive
# @return [nil] nothing
Accept the given attributes, converting each value to the appropriate
type, constructing included models and collections, and other triggers as
defined.

Use `#receive!` to accept 'dirty' data -- from JSON, from a nested hash,
or some such. Use `#update_attributes` if your data is already type safe.
Accept the given attributes converting each value to the appropriate type constructing included models and collections and other triggers as defined . Use ` #receive! ` to accept ' dirty ' data -- from JSON from a nested hash or some such . Use ` #update_attributes ` if your data is already type safe .
def receive!(hsh={})
      if hsh.respond_to?(:attributes)
        hsh = hsh.attributes
      else
        Gorillib::Model::Validate.hashlike!(hsh){ "attributes for #{self.inspect}" }
        hsh = hsh.dup
      end
      self.class.field_names.each do |field_name|
        if    hsh.has_key?(field_name)      then val = hsh.delete(field_name)
        elsif hsh.has_key?(field_name.to_s) then val = hsh.delete(field_name.to_s)
        else next ; end
        self.send("receive_#{field_name}", val)
      end
      handle_extra_attributes(hsh)
      nil
    end
def receive! ( hsh = { } ) if hsh . respond_to? ( :attributes ) hsh = hsh . attributes else Gorillib :: Model :: Validate . hashlike! ( hsh ) { "attributes for #{self.inspect}" } hsh = hsh . dup end self . class . field_names . each do | field_name | if hsh . has_key? ( field_name ) then val = hsh . delete ( field_name ) elsif hsh . has_key? ( field_name . to_s ) then val = hsh . delete ( field_name . to_s ) else next ; end self . send ( "receive_#{field_name}" , val ) end handle_extra_attributes ( hsh ) nil end
Accept the given attributes, converting each value to the appropriate
type, constructing included models and collections, and other triggers as
defined.
Accept the given attributes converting each value to the appropriate type constructing included models and collections and other triggers as defined .
None
nil
hsh
<not_specific>
<not_specific>
hsh The values to receive
hsh The values to receive