Module: Hickey::DomainDetector::Actions
- Defined in:
- lib/hickey/domain_detector/actions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find_action(attribute, record) ⇒ Object
- #visit_hash_with_find_or_create_actions(attribute, record) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/hickey/domain_detector/actions.rb', line 4 def self.included(base) base.send(:alias_method_chain, :visit_hash, :find_or_create_actions) end |
Instance Method Details
#find_action(attribute, record) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hickey/domain_detector/actions.rb', line 24 def find_action(attribute, record) model_type = compute_type(attribute, record) conditions = record.inject({}) do |c, entity| key, value = entity unless [Hash, Array].include?(value.class) #added if to filter column name for fixing hickey on acitverecord 1.2.6 c[key] = value if model_type.column_names.include?(key.to_s) end c end compute_type(attribute, record).find(:first, :conditions => conditions) end |
#visit_hash_with_find_or_create_actions(attribute, record) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hickey/domain_detector/actions.rb', line 8 def visit_hash_with_find_or_create_actions(attribute, record) case record.keys.first when :find record = record[:find] attribute = find_action(attribute, record) when :create record = record[:create] when :find_or_create record = record[:find_or_create] if find_attribute = find_action(attribute, record) attribute = find_attribute end end visit_hash_without_find_or_create_actions(attribute, record) end |