Module: ActiveRecordDecorator::ClassMethods
- Defined in:
- lib/active_record_decorator.rb
Instance Method Summary collapse
- #all_assign_operation_aliases ⇒ Object
- #all_condition_aliases ⇒ Object
- #assign_operation(name, *attributes) ⇒ Object
- #condition_alias(condition_name, *attributes) ⇒ Object
- #has_relation_callback_registered?(rl_class) ⇒ Boolean
- #on_has_many_update(relation_name, method, params = {}) ⇒ Object
- #on_has_one_update(relation_name, method, params = {}) ⇒ Object
- #register_relation_callback(relation_type, relation_name, method, params = {}) ⇒ Object
Instance Method Details
#all_assign_operation_aliases ⇒ Object
124 125 126 |
# File 'lib/active_record_decorator.rb', line 124 def all_assign_operation_aliases self.assign_operation_aliases end |
#all_condition_aliases ⇒ Object
103 104 105 |
# File 'lib/active_record_decorator.rb', line 103 def all_condition_aliases self.condition_aliases end |
#assign_operation(name, *attributes) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_record_decorator.rb', line 107 def assign_operation(name, *attributes) defaults = attributes..dup condition_name = name if self.instance_methods(false).include?(condition_name.to_sym) raise "already method defined" end attr = defaults[:attr] value = defaults[:value] return if self.assign_operation_aliases.detect { |rl| rl.name == condition_name } self.assign_operation_aliases << AssignOperationCore::Operation.new(condition_name, attr, value) delegate name.to_sym, to: :assign_operation_proxy end |
#condition_alias(condition_name, *attributes) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/active_record_decorator.rb', line 92 def condition_alias(condition_name, *attributes) defaults = attributes..dup condition_name = condition_name operator = defaults[:operator] attr = defaults[:attr] value = defaults[:value] return if self.condition_aliases.detect { |rl| rl.name == condition_name } self.condition_aliases << ConditionEvaluatorCore::Condition.new(condition_name, attr, operator, value) end |
#has_relation_callback_registered?(rl_class) ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/active_record_decorator.rb', line 81 def has_relation_callback_registered?(rl_class) status = false self.relation_callback_chain.each do |cb| if cb.relation_class_match?(rl_class) status = true break end end return status end |
#on_has_many_update(relation_name, method, params = {}) ⇒ Object
70 71 72 |
# File 'lib/active_record_decorator.rb', line 70 def on_has_many_update(relation_name, method, params = {}) register_relation_callback(:has_many, relation_name, method, params) end |
#on_has_one_update(relation_name, method, params = {}) ⇒ Object
66 67 68 |
# File 'lib/active_record_decorator.rb', line 66 def on_has_one_update(relation_name, method, params = {}) register_relation_callback(:has_one, relation_name, method, params) end |
#register_relation_callback(relation_type, relation_name, method, params = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/active_record_decorator.rb', line 74 def register_relation_callback(relation_type, relation_name, method, params = {}) return if self.relation_callback_chain.detect { |rl| rl.relation_name == relation_name } rl_reflects = self.reflect_on_all_associations(relation_type) rl_reflect = rl_reflects.find { |rl| rl.name == relation_name } self.relation_callback_chain << Callback.new(relation_type, relation_name, rl_reflect.klass, method) end |