Class: MongoModel::Associations::HasManyByIds::Proxy

Inherits:
Base::Proxy
  • Object
show all
Defined in:
lib/mongomodel/concerns/associations/has_many_by_ids.rb

Constant Summary

OVERRIDE_METHODS =

Pass these methods to the association class rather than the Array target

[ :find ]

Instance Attribute Summary

Attributes inherited from Base::Proxy

#association

Instance Method Summary (collapse)

Methods inherited from Base::Proxy

#initialize, #loaded!, #loaded?, #proxy_respond_to?, #reset, #respond_to?, #target, #target=

Constructor Details

This class inherits a constructor from MongoModel::Associations::Base::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_id, *args, &block) (private)



188
189
190
191
192
193
194
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 188

def method_missing(method_id, *args, &block)
  if target.respond_to?(method_id) && !OVERRIDE_METHODS.include?(method_id.to_sym)
    super(method_id, *args, &block)
  else
    association.scoped.send(method_id, *args, &block)
  end
end

Instance Method Details

- (Object) <<(doc)



117
118
119
120
121
122
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 117

def <<(doc)
  ensure_class(doc)
  super if loaded?
  ids << doc.id
  self
end

- (Object) []=(index, doc)



110
111
112
113
114
115
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 110

def []=(index, doc)
  ensure_class(doc)
  super if loaded?
  ids[index] = doc.id
  self
end

- (Object) build(*args, &block)



98
99
100
101
102
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 98

def build(*args, &block)
  doc = association.build(*args, &block)
  self << doc
  doc
end

- (Object) clear



159
160
161
162
163
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 159

def clear
  super if loaded?
  ids.clear
  self
end

- (Object) concat(documents)



124
125
126
127
128
129
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 124

def concat(documents)
  ensure_class(documents)
  super if loaded?
  ids.concat(documents.map { |doc| doc.id })
  self
end

- (Object) create(*args, &block)



104
105
106
107
108
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 104

def create(*args, &block)
  doc = association.create(*args, &block)
  self << doc
  doc
end

- (Object) delete(doc)



165
166
167
168
169
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 165

def delete(doc)
  super if loaded?
  ids.delete(doc.id)
  self
end

- (Object) delete_at(index)



171
172
173
174
175
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 171

def delete_at(index)
  super if loaded?
  ids.delete_at(index)
  self
end

- (Object) delete_if(&block)



177
178
179
180
181
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 177

def delete_if(&block)
  super
  ids.replace(map { |doc| doc.id })
  self
end

- (Object) ids



183
184
185
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 183

def ids
  association.ids
end

- (Object) insert(index, doc)



131
132
133
134
135
136
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 131

def insert(index, doc)
  ensure_class(doc)
  super if loaded?
  ids.insert(index, doc.id)
  self
end

- (Object) push(*documents)



145
146
147
148
149
150
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 145

def push(*documents)
  ensure_class(documents)
  super if loaded?
  ids.push(*documents.map { |doc| doc.id })
  self
end

- (Object) replace(documents)



138
139
140
141
142
143
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 138

def replace(documents)
  ensure_class(documents)
  super if loaded?
  ids.replace(documents.map { |doc| doc.id })
  self
end

- (Object) unshift(*documents)



152
153
154
155
156
157
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 152

def unshift(*documents)
  ensure_class(documents)
  super if loaded?
  ids.unshift(*documents.map { |doc| doc.id })
  self
end