Class: ActsAsCalculator::ResolveImportOwner

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

Overview

{"owner": {"type": "Company", "id": 7}} — omitted means the global (nil-owner) row, which is what a single-tenant host wants and what FindOwnedRecord falls back to.

Class Method Summary collapse

Class Method Details

.call(reference) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/acts_as_calculator/resolve_import_owner.rb', line 7

def self.call(reference)
  return nil if reference.nil?

  attributes = symbolize(reference)
  model = model_for(attributes[:type])
  id = attributes[:id]
  raise ImportError, "owner reference #{reference.inspect} needs both a type and an id" if id.nil?

  model.find_by(model.primary_key => id) ||
    raise(ImportError, "no #{model.name} with id #{id.inspect} to own the imported record")
end