Class: Mongify::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/mongify/configuration.rb

Overview

Handles all tasks regarding the connection to sql and no-sql database It also handles the parsing of the data

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.in_streamObject

Returns the value of attribute in_stream.



8
9
10
# File 'lib/mongify/configuration.rb', line 8

def in_stream
  @in_stream
end

.out_streamObject

Returns the value of attribute out_stream.



8
9
10
# File 'lib/mongify/configuration.rb', line 8

def out_stream
  @out_stream
end

Class Method Details

.parse(file_name) ⇒ Object

Parses a external configuration file and evaluates it and returns a instence of a configuration class



11
12
13
14
15
16
# File 'lib/mongify/configuration.rb', line 11

def parse(file_name)
  raise Mongify::ConfigurationFileNotFound, "File #{file_name} is missing" unless File.exists?(file_name)
  config = self.new
  config.instance_eval(File.read(file_name))
  config
end

Instance Method Details

#mongodb_connection(options = {}, &block) ⇒ Object

Returns a no_sql_connection which is bound to a mongodb adapter or builds a new no_sql_connection if block is given



22
23
24
25
26
27
# File 'lib/mongify/configuration.rb', line 22

def mongodb_connection(options={}, &block)
  return @mongodb_conncetion if @mongodb_connection and !block_given?
  options.stringify_keys!
  options['adapter'] ||= 'mongodb'
  @mongodb_connection = no_sql_connection(options, &block)
end

#no_sql_connection(options = {}, &block) ⇒ Object

Returns a sql_connection If a block is given, it will be executed on the connection For more information, see Database::NoSqlConnection



41
42
43
44
45
# File 'lib/mongify/configuration.rb', line 41

def no_sql_connection(options={}, &block)
  @no_sql_connection ||= Mongify::Database::NoSqlConnection.new(options)
  @no_sql_connection.instance_exec(&block) if block_given?
  @no_sql_connection
end

#sql_connection(options = {}, &block) ⇒ Object

Returns a sql_connection If a block is given, it will be executed on the connection For more information, see Database::SqlConnection



32
33
34
35
36
# File 'lib/mongify/configuration.rb', line 32

def sql_connection(options={}, &block)
  @sql_connection ||= Mongify::Database::SqlConnection.new(options)
  @sql_connection.instance_exec(&block) if block_given?
  @sql_connection
end