Class: Jsapi::Meta::BaseReference

Inherits:
Base
  • Object
show all
Defined in:
lib/jsapi/meta/base_reference.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #inspect

Methods included from Attributes::ClassMethods

#attribute, #attribute_names

Constructor Details

This class inherits a constructor from Jsapi::Meta::Base

Class Method Details

.lookup_method_nameObject

Returns the name of the method to be invoked to look up the referred object in a Definitions instance.



13
14
15
16
# File 'lib/jsapi/meta/base_reference.rb', line 13

def self.lookup_method_name
  @lookup_method_name ||=
    name.delete_suffix('::Reference').demodulize.underscore
end

Instance Method Details

#refObject

:attr: ref The name of the referred object.



9
# File 'lib/jsapi/meta/base_reference.rb', line 9

attribute :ref, String

#reference?Boolean

:nodoc:

Returns:

  • (Boolean)


18
19
20
# File 'lib/jsapi/meta/base_reference.rb', line 18

def reference? # :nodoc:
  true
end

#resolve(definitions) ⇒ Object

Resolves ref by looking up the object with that name in definitions.

Raises a ReferenceError if ref could not be resolved.

Raises:



25
26
27
28
29
30
# File 'lib/jsapi/meta/base_reference.rb', line 25

def resolve(definitions)
  object = definitions.send(self.class.lookup_method_name, ref)
  raise ReferenceError, ref if object.nil?

  object.resolve(definitions)
end