Class: Domotics::Core::DataMongoOperator
- Inherits:
- BasicObject
- Defined in:
- lib/domotics/core/data/data_mongo.rb
Instance Method Summary collapse
-
#initialize(coll, element) ⇒ DataMongoOperator
constructor
A new instance of DataMongoOperator.
- #method_missing(symbol, *args) ⇒ Object
Constructor Details
#initialize(coll, element) ⇒ DataMongoOperator
Returns a new instance of DataMongoOperator.
17 18 19 20 |
# File 'lib/domotics/core/data/data_mongo.rb', line 17 def initialize(coll, element) @coll = coll @element = element end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/domotics/core/data/data_mongo.rb', line 22 def method_missing(symbol, *args) # Setter method [*=(value)] if symbol.to_s =~ /.*=\Z/ and args.size == 1 if el = @coll.find_one("element" => @element) @coll.update({ "_id" => el["_id"] }, { "element" => @element, symbol.to_s[0..-2] => args[0] }) else @coll.insert("element" => @element, symbol.to_s[0..-2] => args[0]) end # Getter method (no arguments allowed) elsif args.size == 0 result = @coll.find_one("element" => @element) result && result[symbol.to_s] else nil end end |