Module: DCA::Storage::ClassMethods

Defined in:
lib/dca/storage/storage.rb

Instance Method Summary collapse

Instance Method Details

#establish_connection(config_name = :db) ⇒ Object



6
7
8
# File 'lib/dca/storage/storage.rb', line 6

def establish_connection config_name = :db
  @config = APP_CONFIG[config_name]
end

#root_storageObject



10
11
12
13
14
15
16
# File 'lib/dca/storage/storage.rb', line 10

def root_storage
  return @storage if @storage

  return storage if @config

  superclass.root_storage if superclass != Object
end

#storageObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dca/storage/storage.rb', line 18

def storage
  return @storage unless @storage.nil?

  if @config
    driver_class = "DCA::#{@config[:driver]}Storage".constantize
    connection = driver_class.establish_connection @config
    @storage = driver_class.new connection, self, @config
  else
    @storage = superclass.root_storage.context self
  end
end