Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cache setter_method_names per class

  • Loading branch information...
commit 18ce87dc24950b5cc3783346c02b55e1c7604865 1 parent f807c64
@thomsbg authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/her/model/orm.rb
View
10 lib/her/model/orm.rb
@@ -29,8 +29,7 @@ def self.initialize_collection(klass, parsed_data={}) # {{{
# Use setter methods of model for each key / value pair in params
# Return key / value pairs for which no setter method was defined on the model
def self.use_setter_methods(model, params) # {{{
- setter_method_names = model.methods.select { |m| m.to_s.end_with?('=') }
- setter_method_names.map! { |m| m.to_s }
+ setter_method_names = model.class.setter_method_names
params.inject({}) do |memo, (key, value)|
setter_method = key.to_s + '='
if setter_method_names.include?(setter_method)
@@ -242,6 +241,13 @@ def destroy_existing(id, params={}) # {{{
new(parsed_data[:data])
end
end # }}}
+
+ def setter_method_names
+ @setter_method_names ||= instance_methods.inject(Set.new) do |memo, method_name|
+ memo << method_name.to_s if method_name.to_s.end_with?('=')
+ memo
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.