Class: ActsAsCalculator::ResolveVariables

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_calculator/resolve_variables.rb

Constant Summary collapse

SOURCE_TYPES =
%i[attribute method lookup context].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specs:, calculable: nil, context: {}, lookups: {}) ⇒ ResolveVariables

Returns a new instance of ResolveVariables.



11
12
13
14
15
16
# File 'lib/acts_as_calculator/resolve_variables.rb', line 11

def initialize(specs:, calculable: nil, context: {}, lookups: {})
  @specs = specs
  @calculable = calculable
  @context = context
  @lookups = lookups
end

Class Method Details

.callObject



7
8
9
# File 'lib/acts_as_calculator/resolve_variables.rb', line 7

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



18
19
20
21
22
# File 'lib/acts_as_calculator/resolve_variables.rb', line 18

def call
  variables.each_with_object({}) do |spec, inputs|
    inputs[spec.name] = resolve(spec)
  end
end