class MaxML::MongoPersistence
Constants
- DEFAULT_CONFIG
Attributes
config[R]
Public Class Methods
new()
click to toggle source
# File lib/maxml/mongo_persistence.rb, line 14 def initialize @config = DEFAULT_CONFIG.dup end
validate_config(opts)
click to toggle source
# File lib/maxml/mongo_persistence.rb, line 33 def self.validate_config(opts) raise Errors::InvalidConfig unless opts.is_a? Hash required_keys = [:host, :port, :database, :collection] required_keys.each do |key| unless opts.has_key?(key) raise Errors::InvalidConfigOption.new(key) end end end
Public Instance Methods
config=(opts)
click to toggle source
# File lib/maxml/mongo_persistence.rb, line 18 def config=(opts) conf = DEFAULT_CONFIG.merge(opts) self.class.validate_config(conf) @config = conf end
save(hash)
click to toggle source
# File lib/maxml/mongo_persistence.rb, line 24 def save(hash) self.class.validate_config(@config) client = MongoClient.new(@config[:host], @config[:port]) db = client.db(@config[:database]) coll = db.collection(@config[:collection]) coll.insert(hash) end