Class: AppConfig::Storage::Mongo
- Defined in:
- lib/app_config/storage/mongo.rb
Overview
Mongo storage method.
Constant Summary collapse
- DEFAULTS =
{ host: 'localhost', port: 27017, database: 'app_config', collection: 'app_config', username: nil, password: nil, }
Instance Method Summary collapse
-
#initialize(options) ⇒ Mongo
constructor
A new instance of Mongo.
-
#reload! ⇒ Object
Reload the data from storage.
-
#save! ⇒ Object
Saves the data back to Mongo.
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ Mongo
Returns a new instance of Mongo.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/app_config/storage/mongo.rb', line 18 def initialize() # Allows passing `true` as an option. if .is_a?(Hash) = DEFAULTS.merge() else = DEFAULTS end setup_connection! fetch_data! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AppConfig::Storage::Base
Instance Method Details
#reload! ⇒ Object
Reload the data from storage. Returns ‘true`/`false`.
31 32 33 |
# File 'lib/app_config/storage/mongo.rb', line 31 def reload! fetch_data! end |
#save! ⇒ Object
Saves the data back to Mongo. Returns ‘true`/`false`.
36 37 38 39 40 41 42 43 44 |
# File 'lib/app_config/storage/mongo.rb', line 36 def save! if @_id retval = collection.update({ '_id' => @_id}, @data.to_hash) else retval = collection.save(@data.to_hash) end !!retval end |