lib/rest_model.rb in rest_model-0.1.11 vs lib/rest_model.rb in rest_model-0.1.12

- old
+ new

@@ -46,20 +46,24 @@ def initialize(attrs = {}) return if attrs.nil? or attrs.empty? attrs = attrs.with_indifferent_access + assign_non_keys_attrs(attrs) + self.class.keys.each do |key| __send__("#{key.name}=", key.from_hash(attrs[key.name])) if key.present?(self) end end def update_attributes(attrs = {}) return if attrs.nil? or attrs.empty? attrs = attrs.with_indifferent_access + assign_non_keys_attrs(attrs) + self.class.keys.each do |key| value = attrs[key.name] if value and key.present?(self) __send__("#{key.name}=", key.from_hash(value, __send__(key.name))) @@ -93,8 +97,19 @@ @convert_input_keys = converter if converter @convert_input_keys end def self.not_allowed_names - %w(resource_id resource link) + %w(resource_id resource) + end + + private + + def assign_non_keys_attrs(attrs) + key_names = self.class.keys.map {|k| k.name} + non_keys = attrs.reject {|k, v| key_names.member?(k.to_sym)} + + non_keys.each do |key, value| + __send__("#{key}=", value) if self.respond_to?("#{key}=") + end end end