Skip to content

Commit

Permalink
Cache setter_method_names per class
Browse files Browse the repository at this point in the history
  • Loading branch information
thomsbg committed Sep 4, 2012
1 parent f807c64 commit 18ce87d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/her/model/orm.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 18ce87d

Please sign in to comment.