Class: OceanDynamo::Associations::CollectionProxy

Inherits:
Relation
  • Object
show all
Defined in:
lib/ocean-dynamo/associations/collection_proxy.rb

Instance Attribute Summary

Attributes inherited from Relation

#klass, #loaded

Instance Method Summary collapse

Constructor Details

#initialize(klass, association) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.



40
41
42
43
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 40

def initialize(klass, association)
  @association = association
  super klass
end

Instance Method Details

#<<(*records) ⇒ Object Also known as: push, append



190
191
192
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 190

def <<(*records)
  proxy_association.concat(records) && self
end

#==(other) ⇒ Object



179
180
181
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 179

def ==(other)
  load_target == other
end

#any?(&block) ⇒ Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 164

def any?(&block)
  @association.any?(&block)
end

#build(attributes = {}, &block) ⇒ Object Also known as: new



86
87
88
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 86

def build(attributes = {}, &block)
  @association.build(attributes, &block)
end

#clearObject



117
118
119
120
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 117

def clear
  delete_all
  self
end

#concat(*records) ⇒ Object



102
103
104
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 102

def concat(*records)
  @association.concat(*records)
end

#count(column_name = nil, options = {}) ⇒ Object



144
145
146
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 144

def count(column_name = nil, options = {})
  @association.count(column_name, options)
end

#create(attributes = {}, &block) ⇒ Object



92
93
94
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 92

def create(attributes = {}, &block)
  @association.create(attributes, &block)
end

#create!(attributes = {}, &block) ⇒ Object



97
98
99
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 97

def create!(attributes = {}, &block)
  @association.create!(attributes, &block)
end

#delete(*records) ⇒ Object



128
129
130
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 128

def delete(*records)
  @association.delete(*records)
end

#delete_allObject



112
113
114
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 112

def delete_all
  @association.delete_all
end

#destroy(*records) ⇒ Object



133
134
135
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 133

def destroy(*records)
  @association.destroy(*records)
end

#destroy_allObject



123
124
125
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 123

def destroy_all
  @association.destroy_all
end

#distinctObject Also known as: uniq



138
139
140
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 138

def distinct
  @association.distinct
end

#empty?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 159

def empty?
  @association.empty?
end

#find(*args, &block) ⇒ Object



71
72
73
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 71

def find(*args, &block)
  @association.find(*args, &block)
end

#first(*args) ⇒ Object



76
77
78
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 76

def first(*args)
  @association.first(*args)
end

#include?(record) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 174

def include?(record)
  @association.include?(record)
end

#last(*args) ⇒ Object



81
82
83
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 81

def last(*args)
  @association.last(*args)
end

#lengthObject



154
155
156
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 154

def length
  @association.length
end

#load_targetObject



56
57
58
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 56

def load_target
  @association.load_target
end

#loaded?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 61

def loaded?
  @association.loaded?
end

#many?(&block) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 169

def many?(&block)
  @association.many?(&block)
end

#prepend(*args) ⇒ Object

Raises:

  • (NoMethodError)


197
198
199
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 197

def prepend(*args)
  raise NoMethodError, "prepend on association is not defined. Please use << or append"
end

#proxy_associationObject



46
47
48
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 46

def proxy_association
  @association
end

#reloadObject



202
203
204
205
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 202

def reload
  proxy_association.reload
  self
end

#replace(other_array) ⇒ Object



107
108
109
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 107

def replace(other_array)
  @association.replace(other_array)
end

#select(select = nil, &block) ⇒ Object



66
67
68
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 66

def select(select = nil, &block)
  @association.select(select, &block)
end

#sizeObject



149
150
151
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 149

def size
  @association.size
end

#targetObject



51
52
53
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 51

def target
  @association.target
end

#to_aryObject Also known as: to_a



184
185
186
# File 'lib/ocean-dynamo/associations/collection_proxy.rb', line 184

def to_ary
  load_target.dup
end