Class: Jsapi::Meta::Base::Reference

Inherits:
Model
  • Object
show all
Defined in:
lib/jsapi/meta/base/reference.rb

Overview

The base reference class.

Constant Summary

Constants included from Attributes

Attributes::DEFAULT_ARRAY, Attributes::DEFAULT_HASH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #merge!

Methods included from Attributes

#attribute, #attribute_names

Constructor Details

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

Class Method Details

.component_typeObject

Derrives the component type from the inner most module name.



14
15
16
# File 'lib/jsapi/meta/base/reference.rb', line 14

def self.component_type
  @component_type ||= name.split('::')[-2].underscore
end

Instance Method Details

#refObject

:attr: ref The name of the referred object.



11
# File 'lib/jsapi/meta/base/reference.rb', line 11

attribute :ref, String

#reference?Boolean

Returns true.

Returns:

  • (Boolean)


19
20
21
# File 'lib/jsapi/meta/base/reference.rb', line 19

def reference?
  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:



26
27
28
29
30
31
# File 'lib/jsapi/meta/base/reference.rb', line 26

def resolve(definitions)
  object = definitions.send("find_#{self.class.component_type}", ref)
  raise ReferenceError, ref if object.nil?

  object.resolve(definitions)
end