Class: Apia::Polymorph
- Inherits:
-
Object
- Object
- Apia::Polymorph
- Extended by:
- Defineable
- Defined in:
- lib/apia/polymorph.rb
Direct Known Subclasses
Class Method Summary collapse
-
.collate_objects(set) ⇒ void
Collate all objects that this polymorph references and add them to the given object set.
-
.definition ⇒ Apia::Definitions::Polymorph
Return the definition for this polymorph.
-
.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.
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
27 28 29 30 31 |
# File 'lib/apia/polymorph.rb', line 27 def collate_objects(set) definition..each_value do |opt| set.add_object(opt.type.klass) if opt.type.usable_for_field? end end |
.definition ⇒ Apia::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..values.find do |opt| opt.matches?(value) end if option.nil? raise InvalidPolymorphValueError.new(self, value) end option end |