Class: Mongoid::MapReduce::Document
- Inherits:
-
Hash
- Object
- Hash
- Mongoid::MapReduce::Document
- Defined in:
- lib/mongoid/mapreduce/document.rb
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Document
constructor
Accept a hash of attributes dring initialization.
-
#method_missing(sym, *args, &block) ⇒ Object
Allow dot notation on our Document.
-
#to_hash ⇒ Object
Converts the Results to a Hash.
Constructor Details
#initialize(attrs) ⇒ Document
Accept a hash of attributes dring initialization
attrs - Hash of attributes to initialize with
Returns value of super
11 12 13 14 15 16 |
# File 'lib/mongoid/mapreduce/document.rb', line 11 def initialize(attrs) attrs.each do |k, v| self[k] = v end super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Allow dot notation on our Document
sym - Symbol/String of the missing value args - Arguments supplied block - Block supplied
Returns value of supplied symbol/string if exists
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongoid/mapreduce/document.rb', line 25 def method_missing(sym, *args, &block) if self.has_key?(sym) return self[sym] elsif self.has_key?(sym.to_sym) return self[sym.to_sym] elsif self.has_key?(sym.to_s) return self[sym.to_s] end super end |
Instance Method Details
#to_hash ⇒ Object
Converts the Results to a Hash
Returns Hash
39 40 41 42 43 44 45 |
# File 'lib/mongoid/mapreduce/document.rb', line 39 def to_hash h = Hash.new self.each do |k, v| h[k.to_s] = v unless [:_key_name, :_key_value].include?(k) end h end |