Class: NaranyaEcm::Rest::Associations::Association
- Inherits:
-
Object
- Object
- NaranyaEcm::Rest::Associations::Association
- Defined in:
- lib/naranya_ecm/rest/associations.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#associated_class ⇒ Object
readonly
Returns the value of attribute associated_class.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(klass, name, options = {}) ⇒ Association
constructor
A new instance of Association.
- #resolve_class_name(given_class_name) ⇒ Object
Constructor Details
#initialize(klass, name, options = {}) ⇒ Association
Returns a new instance of Association.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/naranya_ecm/rest/associations.rb', line 14 def initialize(klass, name, = {}) @klass, @name = klass, name @associated_class = if (given_class_name = .delete(:class_name)) resolve_class_name(given_class_name) else resolve_class_name(name.to_s.classify.to_sym) end @options = .with_indifferent_access klass.send :attr_accessor, name end |
Instance Attribute Details
#associated_class ⇒ Object (readonly)
Returns the value of attribute associated_class.
7 8 9 |
# File 'lib/naranya_ecm/rest/associations.rb', line 7 def associated_class @associated_class end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/naranya_ecm/rest/associations.rb', line 7 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/naranya_ecm/rest/associations.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/naranya_ecm/rest/associations.rb', line 7 def @options end |
Instance Method Details
#resolve_class_name(given_class_name) ⇒ Object
9 10 11 12 |
# File 'lib/naranya_ecm/rest/associations.rb', line 9 def resolve_class_name(given_class_name) given_class_name = "#{@klass.name.deconstantize}::#{given_class_name}" if given_class_name.is_a?(Symbol) given_class_name.constantize end |