Class: MongoDoc::Associations::CollectionProxy
- Includes:
- ProxyBase
- Defined in:
- lib/mongo_doc/associations/collection_proxy.rb
Constant Summary collapse
- ARRAY_METHODS =
List of array methods (that are not in
Object
) that need to be delegated tocollection
. (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
- MUST_DEFINE =
List of additional methods that must be delegated to
collection
. %w[to_a to_ary inspect to_bson ==]
- DO_NOT_DEFINE =
%w[concat insert replace]
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
- #<<(item) ⇒ Object (also: #push)
- #[]=(index, item) ⇒ Object (also: #insert)
- #_append ⇒ Object
- #_modifier_path=(path) ⇒ Object
- #_root=(value) ⇒ Object
- #_unshift ⇒ Object
- #add ⇒ Object
- #build(attrs) ⇒ Object
- #concat(array) ⇒ Object
-
#initialize(options) ⇒ CollectionProxy
constructor
A new instance of CollectionProxy.
-
#is_a?(klass) ⇒ Boolean
(also: #kind_of?)
Lie about our class.
- #replace(other) ⇒ Object
- #unshift(item) ⇒ Object
- #valid? ⇒ Boolean
Methods included from ProxyBase
Constructor Details
#initialize(options) ⇒ CollectionProxy
Returns a new instance of CollectionProxy.
52 53 54 55 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 52 def initialize() @collection = [] super end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
25 26 27 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 25 def collection @collection end |
Instance Method Details
#<<(item) ⇒ Object Also known as: push
58 59 60 61 62 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 58 def <<(item) attach(item) _append item self end |
#[]=(index, item) ⇒ Object Also known as: insert
66 67 68 69 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 66 def []=(index, item) attach(item) add(index, item) end |
#_append ⇒ Object
57 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 57 alias _append << |
#_modifier_path=(path) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 27 def _modifier_path=(path) super collection.each do |item| item._modifier_path = _modifier_path + '.$' if ProxyBase.is_document?(item) end end |
#_root=(value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 34 def _root=(value) @_root = value collection.each do |item| item._root = value if ProxyBase.is_document?(item) end end |
#_unshift ⇒ Object
95 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 95 alias _unshift unshift |
#add ⇒ Object
65 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 65 alias add []= |
#build(attrs) ⇒ Object
72 73 74 75 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 72 def build(attrs) item = _assoc_class.new(attrs) push(item) end |
#concat(array) ⇒ Object
77 78 79 80 81 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 77 def concat(array) array.each do |item| push(item) end end |
#is_a?(klass) ⇒ Boolean Also known as: kind_of?
Lie about our class. Borrowed from Rake::FileList Note: Does not work for case equality (===
)
85 86 87 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 85 def is_a?(klass) klass == Array || super(klass) end |
#replace(other) ⇒ Object
90 91 92 93 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 90 def replace(other) clear concat(other) end |
#unshift(item) ⇒ Object
96 97 98 99 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 96 def unshift(item) attach(item) _unshift(item) end |
#valid? ⇒ Boolean
101 102 103 104 105 106 107 108 109 |
# File 'lib/mongo_doc/associations/collection_proxy.rb', line 101 def valid? all? do |child| if ProxyBase.is_document?(child) child.valid? else true end end end |