Module: ActiveRecordDecorator

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_record_decorator.rb

Defined Under Namespace

Modules: ClassMethods Classes: Callback

Instance Method Summary collapse

Instance Method Details

#assign_operation_proxyObject



153
154
155
# File 'lib/active_record_decorator.rb', line 153

def assign_operation_proxy
  @assign_operation_proxy ||=  ActiveRecordDecorator::AssignOperation.new(record: self)
end

#condition_match?(condition_to_evaluate) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/active_record_decorator.rb', line 149

def condition_match?(condition_to_evaluate)
  ActiveRecordDecorator::ConditionEvaluator.new(record: self, condition_to_evaluate: condition_to_evaluate).evaluate
end

#run_callback_for_relation_class(rl_class, model) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/active_record_decorator.rb', line 140

def run_callback_for_relation_class(rl_class, model)
  rl_class.relation_callback_chain.each do |cb|
    if cb.relation_class_match?(self.class)
      rl = self.class.reflect_on_all_associations(:belongs_to).find { |rl_reflect| rl_reflect.klass == rl_class }
      model.send(rl.name).send(cb.method_name) if rl
    end
  end
end

#run_callbacks_registeredObject



130
131
132
133
134
135
136
137
138
# File 'lib/active_record_decorator.rb', line 130

def run_callbacks_registered()
  relations = self.class.reflect_on_all_associations(:belongs_to)
  relations.each do |rl|
    rl_class = rl.klass
    if rl_class.respond_to?(:has_relation_callback_registered?) && rl_class.has_relation_callback_registered?(self.class)
      run_callback_for_relation_class(rl_class, self)
    end
  end
end