Sha256: c31ef07e6e838300455c89f6e24172034560617a7a8e8bdb520b01ab2ff680fe

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

Mongo.metaclass_eval do
  def db name
    config = rad.models.db[name.to_s] || raise("no database config for #{name} alias!")
    host, port, options = config['host'], config['port'], (config['options'] || {})
    connection = self.connection host, port, options
    db_name = config['name'] || raise("no database name for #{name} alias!")
    connection.db db_name
  end
  cache_method_with_params :db

  def connection host, port, options
    options[:logger] = rad.logger unless options.include? :logger
    Mongo::Connection.new host, port, options
  end
  cache_method_with_params :connection
end

FileModel.metaclass_eval do
  def box name
    raise 'invalid box name' unless name == :default

    config = rad.models.fs
    driver_class = config['driver_class'] || raise("driver for FileModel not defined!")
    _class = eval driver_class, TOPLEVEL_BINDING, __FILE__, __LINE__
    options = config['options'] || {}
    driver = _class.new options
    Vos::Box.new driver
  end
  cache_method_with_params :box
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rad_kit-0.0.10 lib/kit/models/config.rb
rad_kit-0.0.9 lib/kit/models/config.rb