class IntegratedData::Entity::Lookup

Public Class Methods

cache_keys() click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 7
def cache_keys
  [:identifier, :source, :strategy, :extractor, :options]
end

Public Instance Methods

cache_keys() click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 12
def cache_keys
  self.class.cache_keys.map do |key|
    send key
  end
end
extract(data, attribute) click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 22
def extract(data, attribute)
  if extractor
    extractor.call data, attribute
  else
    default_extractor data, attribute
  end
end
perform(value) click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 18
def perform(value)
  source.build(options).public_send(strategy, id, prepare(value))
end

Private Instance Methods

default_extractor(data, attribute) click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 38
def default_extractor(data, attribute)
  if data.respond_to? :extract
    data.extract attribute
  elsif data.respond_to? :to_h
    data.to_h[attribute]
  elsif data.respond_to? attribute
    data.public_send attribute
  else
    raise Error, "couldn't extract #{attribute} from #{data.class}"
  end
end
prepare(value) click to toggle source
# File lib/integrated_data/entity/lookup.rb, line 34
def prepare(value)
  identifier ? identifier.parse(value) : value
end