class AttributeDependsCalculator::Parameter
Constants
- METHODS
- OPERATORS
Attributes
depend_association_name[RW]
depend_column[RW]
expression[RW]
operator[RW]
params[RW]
Public Class Methods
new(params)
click to toggle source
# File lib/attribute_depends_calculator/parameter.rb, line 9 def initialize(params) self.operator = params.values_at(:operator).first || :sum self.params = params fetch end
Public Instance Methods
callback()
click to toggle source
# File lib/attribute_depends_calculator/parameter.rb, line 37 def callback @proc end
fetch()
click to toggle source
# File lib/attribute_depends_calculator/parameter.rb, line 15 def fetch self.depend_association_name = params.keys.first self.depend_column = params.values.first operator_filter end
operator_filter()
click to toggle source
# File lib/attribute_depends_calculator/parameter.rb, line 21 def operator_filter self.expression = if OPERATORS.include? operator "pluck(:#{depend_column}).compact.reduce(0, :#{operator})" elsif METHODS.include? operator "#{operator}(:#{depend_column})" elsif operator.kind_of? Proc @proc = operator else raise 'The operator of depends calculator are incorrect' end end
proc?()
click to toggle source
# File lib/attribute_depends_calculator/parameter.rb, line 33 def proc? !@proc.nil? end