Class: MongoDoc::Proxy
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 ==]
Instance Attribute Summary collapse
-
#_parent ⇒ Object
Returns the value of attribute _parent.
-
#_root ⇒ Object
Returns the value of attribute _root.
-
#assoc_name ⇒ Object
readonly
Returns the value of attribute assoc_name.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#collection_class ⇒ Object
readonly
Returns the value of attribute collection_class.
Instance Method Summary collapse
- #<<(items) ⇒ Object (also: #push, #concat)
- #append ⇒ Object
-
#initialize(options) ⇒ Proxy
constructor
A new instance of Proxy.
-
#is_a?(klass) ⇒ Boolean
(also: #kind_of?)
Lie about our class.
- #path_to_root(attrs) ⇒ Object
Constructor Details
#initialize(options) ⇒ Proxy
Returns a new instance of Proxy.
33 34 35 36 37 38 39 |
# File 'lib/mongodoc/proxy.rb', line 33 def initialize() @assoc_name = [:assoc_name] @collection = [] @collection_class = [:collection_class] @_root = [:root] @_parent = [:parent] end |
Instance Attribute Details
#_parent ⇒ Object
Returns the value of attribute _parent.
20 21 22 |
# File 'lib/mongodoc/proxy.rb', line 20 def _parent @_parent end |
#_root ⇒ Object
Returns the value of attribute _root.
20 21 22 |
# File 'lib/mongodoc/proxy.rb', line 20 def _root @_root end |
#assoc_name ⇒ Object (readonly)
Returns the value of attribute assoc_name.
20 21 22 |
# File 'lib/mongodoc/proxy.rb', line 20 def assoc_name @assoc_name end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
20 21 22 |
# File 'lib/mongodoc/proxy.rb', line 20 def collection @collection end |
#collection_class ⇒ Object (readonly)
Returns the value of attribute collection_class.
20 21 22 |
# File 'lib/mongodoc/proxy.rb', line 20 def collection_class @collection_class end |
Instance Method Details
#<<(items) ⇒ Object Also known as: push, concat
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongodoc/proxy.rb', line 42 def <<(items) items = [items] unless items.kind_of?(Array) items.each do |item| item = collection_class.new(item) if Hash === item raise NotADocumentError unless collection_class === item append item item._parent = self item._root = _root end self end |
#append ⇒ Object
41 |
# File 'lib/mongodoc/proxy.rb', line 41 alias_method :append, :<< |
#is_a?(klass) ⇒ Boolean Also known as: kind_of?
Lie about our class. Borrowed from Rake::FileList Note: Does not work for case equality (===
)
58 59 60 |
# File 'lib/mongodoc/proxy.rb', line 58 def is_a?(klass) klass == Array || super(klass) end |
#path_to_root(attrs) ⇒ Object
63 64 65 |
# File 'lib/mongodoc/proxy.rb', line 63 def path_to_root(attrs) _parent.path_to_root(attrs) end |