Class: Toy::Reference
Defined Under Namespace
Classes: ReferenceProxy
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(model, name, *args) ⇒ Reference
constructor
A new instance of Reference.
- #instance_variable ⇒ Object
- #key ⇒ Object
- #new_proxy(owner) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(model, name, *args) ⇒ Reference
Returns a new instance of Reference.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/toy/reference.rb', line 5 def initialize(model, name, *args) @model = model @name = name.to_sym @options = args. @type = args.shift model.references[name] = self model.attribute(key, type.key_type) create_accessors end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/toy/reference.rb', line 3 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/toy/reference.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/toy/reference.rb', line 3 def @options end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
32 33 34 35 36 |
# File 'lib/toy/reference.rb', line 32 def eql?(other) self.class.eql?(other.class) && model == other.model && name == other.name end |
#instance_variable ⇒ Object
24 25 26 |
# File 'lib/toy/reference.rb', line 24 def instance_variable @instance_variable ||= :"@_#{name}" end |
#key ⇒ Object
20 21 22 |
# File 'lib/toy/reference.rb', line 20 def key @key ||= :"#{name.to_s.singularize}_id" end |
#new_proxy(owner) ⇒ Object
28 29 30 |
# File 'lib/toy/reference.rb', line 28 def new_proxy(owner) ReferenceProxy.new(self, owner) end |
#type ⇒ Object
16 17 18 |
# File 'lib/toy/reference.rb', line 16 def type @type ||= name.to_s.classify.constantize end |