class Apia::Polymorph

Public Class Methods

collate_objects(set) click to toggle source

Collate all objects that this polymorph references and add them to the given object set

@param set [Apia::ObjectSet] @return [void]

# File lib/apia/polymorph.rb, line 27
def collate_objects(set)
  definition.options.each_value do |opt|
    set.add_object(opt.type.klass) if opt.type.usable_for_field?
  end
end
definition() click to toggle source

Return the definition for this polymorph

@return [Apia::Definitions::Polymorph]

# File lib/apia/polymorph.rb, line 18
def definition
  @definition ||= Definitions::Polymorph.new(Helpers.class_name_to_id(name))
end
option_for_value(value) click to toggle source

Return the type which should be returned for the given value by running through each of the matchers to find the appropriate type.

# File lib/apia/polymorph.rb, line 35
def option_for_value(value)
  option = definition.options.values.find do |opt|
    opt.matches?(value)
  end

  if option.nil?
    raise InvalidPolymorphValueError.new(self, value)
  end

  option
end