Class: Couchbase::Model::Relationship::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/model/relationship/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  self.name = name.to_s
  @auto_save = options[:auto_save]
  @auto_delete = options[:auto_delete]
  @class_name = options[:class_name]
  @auto_load = options.key?(:auto_load) ? options[:auto_load] : true
end

Instance Attribute Details

#auto_deleteObject (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_loadObject (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_saveObject (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_nameObject (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

#nameObject

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_classObject



34
35
36
# File 'lib/couchbase/model/relationship/association.rb', line 34

def child_class
  child_klass.constantize
end

#child_klassObject



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

Returns:

  • (Boolean)


16
17
18
# File 'lib/couchbase/model/relationship/association.rb', line 16

def loaded?(parent)
  parent.send("#{name}_loaded?")
end

#prefixObject



38
39
40
# File 'lib/couchbase/model/relationship/association.rb', line 38

def prefix
  child_class.id_prefix
end