Class: Days::Config

Inherits:
Settingslogic
  • Object
show all
Defined in:
lib/days/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_file = {}, section = nil) ⇒ Config

Returns a new instance of Config.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/days/config.rb', line 18

def initialize(hash_or_file = {}, section = nil)
  super
  if section.nil?
    if String === hash_or_file
      self[:root] = File.dirname(hash_or_file)
    else
      self[:root] = "."
    end

    self['database'].tap do |hash|
      next unless hash
      if hash['adapter'] == 'sqlite3' && /^\// !~ hash['database']
        hash['database'] = File.join(self.root, hash['database'])
      end
    end
  end
end

Class Method Details

.namespace(value = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/days/config.rb', line 8

def self.namespace(value = nil)
  if value
    @namespace = value
  else
    @namespace
  end
end

Instance Method Details

#establish_db_connection(force = false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/days/config.rb', line 37

def establish_db_connection(force=false)
  if Days::App.environment.to_sym == :development && (self.has_key?(:activerecord_log) ? self.activerecord_log == true : true)
    ActiveRecord::Base.logger = Logger.new($stdout)
  end

  begin
    raise ActiveRecord::ConnectionNotEstablished if force
    return ActiveRecord::Base.connection
  rescue ActiveRecord::ConnectionNotEstablished
    ActiveRecord::Base.establish_connection(self['database'] ? Hash[self.database] : ENV["DATABASE_URL"])
    retry
  end
end