Class: Couchbase::Model::Relationship::Association
- Inherits:
-
Object
- Object
- Couchbase::Model::Relationship::Association
- Defined in:
- lib/couchbase/model/relationship/association.rb
Instance Attribute Summary collapse
-
#auto_delete ⇒ Object
readonly
Returns the value of attribute auto_delete.
-
#auto_load ⇒ Object
readonly
Returns the value of attribute auto_load.
-
#auto_save ⇒ Object
readonly
Returns the value of attribute auto_save.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #child_class ⇒ Object
- #child_klass ⇒ Object
- #fetch(parent) ⇒ Object
-
#initialize(name, options = {}) ⇒ Association
constructor
A new instance of Association.
- #load(parent) ⇒ Object
- #loaded?(parent) ⇒ Boolean
- #prefix ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Association
Returns a new instance of Association.
8 9 10 11 12 13 14 |
# File 'lib/couchbase/model/relationship/association.rb', line 8 def initialize(name, = {}) self.name = name.to_s @auto_save = [:auto_save] @auto_delete = [:auto_delete] @class_name = [:class_name] @auto_load = .key?(:auto_load) ? [:auto_load] : true end |
Instance Attribute Details
#auto_delete ⇒ Object (readonly)
Returns the value of attribute auto_delete.
6 7 8 |
# File 'lib/couchbase/model/relationship/association.rb', line 6 def auto_delete @auto_delete end |
#auto_load ⇒ Object (readonly)
Returns the value of attribute auto_load.
6 7 8 |
# File 'lib/couchbase/model/relationship/association.rb', line 6 def auto_load @auto_load end |
#auto_save ⇒ Object (readonly)
Returns the value of attribute auto_save.
6 7 8 |
# File 'lib/couchbase/model/relationship/association.rb', line 6 def auto_save @auto_save end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
6 7 8 |
# File 'lib/couchbase/model/relationship/association.rb', line 6 def class_name @class_name end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/couchbase/model/relationship/association.rb', line 5 def name @name end |
Instance Method Details
#child_class ⇒ Object
34 35 36 |
# File 'lib/couchbase/model/relationship/association.rb', line 34 def child_class child_klass.constantize end |
#child_klass ⇒ Object
30 31 32 |
# File 'lib/couchbase/model/relationship/association.rb', line 30 def child_klass @class_name || name.classify end |
#fetch(parent) ⇒ Object
20 21 22 |
# File 'lib/couchbase/model/relationship/association.rb', line 20 def fetch(parent) parent.send(name) end |
#load(parent) ⇒ Object
24 25 26 27 28 |
# File 'lib/couchbase/model/relationship/association.rb', line 24 def load(parent) child_id = child_class.prefixed_id(parent.id) child_class.find_by_id(child_id) end |
#loaded?(parent) ⇒ Boolean
16 17 18 |
# File 'lib/couchbase/model/relationship/association.rb', line 16 def loaded?(parent) parent.send("#{name}_loaded?") end |
#prefix ⇒ Object
38 39 40 |
# File 'lib/couchbase/model/relationship/association.rb', line 38 def prefix child_class.id_prefix end |