summaryrefslogtreecommitdiff
path: root/lib/hashie/extensions/ignore_undeclared.rb
diff options
context:
space:
mode:
authorVladimir Kochnev <hashtable@yandex.ru>2016-02-07 05:42:30 +0300
committerVladimir Kochnev <hashtable@yandex.ru>2016-02-08 09:37:05 +0300
commitc4fc51d48f92ab2dac1e0d13e152be2e1a1b3b28 (patch)
tree40ba75ec24b113e90f5e564bca08093f1e9e41b4 /lib/hashie/extensions/ignore_undeclared.rb
parentc0c85a68ecb88af00564f74af2889386975bb5a7 (diff)
downloadhashie-c4fc51d48f92ab2dac1e0d13e152be2e1a1b3b28.tar.gz
Refactor IgnoreUndeclared#initialize_attributes.
Diffstat (limited to 'lib/hashie/extensions/ignore_undeclared.rb')
-rw-r--r--lib/hashie/extensions/ignore_undeclared.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/hashie/extensions/ignore_undeclared.rb b/lib/hashie/extensions/ignore_undeclared.rb
index ce113fe..9b506dd 100644
--- a/lib/hashie/extensions/ignore_undeclared.rb
+++ b/lib/hashie/extensions/ignore_undeclared.rb
@@ -30,10 +30,13 @@ module Hashie
# p.email # => NoMethodError
module IgnoreUndeclared
def initialize_attributes(attributes)
+ return unless attributes
+ klass = self.class
+ translations = klass.respond_to?(:translations) && klass.translations
attributes.each_pair do |att, value|
- next unless self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att))
+ next unless klass.property?(att) || (translations && translations.include?(att))
self[att] = value
- end if attributes
+ end
end
def property_exists?(property)