Class: ActsAsCalculator::ImportFormula
- Inherits:
-
Object
- Object
- ActsAsCalculator::ImportFormula
- Defined in:
- lib/acts_as_calculator/import_formula.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(attributes:) ⇒ ImportFormula
constructor
A new instance of ImportFormula.
Constructor Details
#initialize(attributes:) ⇒ ImportFormula
Returns a new instance of ImportFormula.
9 10 11 12 13 14 |
# File 'lib/acts_as_calculator/import_formula.rb', line 9 def initialize(attributes:) @attributes = attributes.transform_keys(&:to_s) @key = @attributes.fetch("key") { raise ImportError, "a formulas entry has no key" }.to_s @scope = (@attributes["scope"] || DEFAULT_SCOPE).to_s @owner = ResolveImportOwner.(@attributes["owner"]) end |
Class Method Details
.call ⇒ Object
5 6 7 |
# File 'lib/acts_as_calculator/import_formula.rb', line 5 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 |
# File 'lib/acts_as_calculator/import_formula.rb', line 16 def call return outcome(:created, add_version(Formula.create!(key:, scope:, owner:))) if formula.nil? return outcome(:skipped, matching_version) if matching_version outcome(:updated, add_version(formula)) end |