Module: Persistence::Base

Included in:
Persistence
Defined in:
lib/persistence/base.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) adapter

Returns the value of attribute adapter



10
11
12
# File 'lib/persistence/base.rb', line 10

def adapter
  @adapter
end

- (Object) file_adapter

Returns the value of attribute file_adapter



11
12
13
# File 'lib/persistence/base.rb', line 11

def file_adapter
  @file_adapter
end

Instance Method Details

- (Object) init_from_yml(file_name, environment = nil)

Initializes persistence from given YAML file.

Parameters:

  • file_name (String)

    File name with YAML config file

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/persistence/base.rb', line 16

def init_from_yml(file_name, environment = nil)
  environment ||= 'development'
  config_hash = YAML.load_file(file_name)[environment]
  raise ArgumentError unless config_hash
  self.init_persistence(config_hash.symbolize_keys)
end

- (Persistence::Base) init_persistence(options = {})

Initializes persitence layer

Parameters:

  • options (Hash) (defaults to: {})

    Config hash

Options Hash (options):

  • :host (String)

    Database name

  • :database (String)

    Database name

  • :collection (String)

    Collection name

Returns:



30
31
32
33
34
# File 'lib/persistence/base.rb', line 30

def init_persistence(options = {})
  self.adapter = Adapters::Mongo.new(options)
  self.file_adapter = Adapters::GridFs.new(database: self.adapter.database)
  self
end