Class: Apia::Polymorph

Inherits:
Object
  • Object
show all
Extended by:
Defineable
Defined in:
lib/apia/polymorph.rb

Direct Known Subclasses

Schema::ObjectSchemaPolymorph

Class Method Summary collapse

Methods included from Defineable

create, inspect, method_missing, name, respond_to_missing?

Class Method Details

.collate_objects(set) ⇒ void

This method returns an undefined value.

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

Parameters:



27
28
29
30
31
# 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

.definitionApia::Definitions::Polymorph

Return the definition for this polymorph



18
19
20
# File 'lib/apia/polymorph.rb', line 18

def definition
  @definition ||= Definitions::Polymorph.new(Helpers.class_name_to_id(name))
end

.option_for_value(value) ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
# 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