Module: DailyConfig

Extended by:
DailyConfig
Included in:
DailyConfig
Defined in:
lib/daily/daily_config.rb

Instance Method Summary collapse

Instance Method Details

#config_init(config) ⇒ Object



50
51
52
53
54
# File 'lib/daily/daily_config.rb', line 50

def config_init(config)
  if !subdirectory.blank?
    config.assets.prefix = "/#{subdirectory}/assets"
  end
end

#database_configObject



34
35
36
# File 'lib/daily/daily_config.rb', line 34

def database_config
  env_hash['database']
end

#database_initObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/daily/daily_config.rb', line 38

def database_init
  db = database_config
  return if db.empty?
  Ruport::Query.add_source :default,
                           :dsn => "dbi:#{db['adapter'].camelize}:database=#{db['database']};host=#{db['host']}", 
                           :user => "#{db['username']}",
                           :password => "#{db['password']}"
                           
  require File.expand_path('../activemetric', __FILE__)
  ActiveMetric::Base.establish_connection db
end

#env_hashObject



25
26
27
# File 'lib/daily/daily_config.rb', line 25

def env_hash
  @env_hash ||= (hash[rails_env] || {})
end

#hashObject



21
22
23
# File 'lib/daily/daily_config.rb', line 21

def hash
  @hash ||= (YAML.load_file("#{rails_root}/config/daily.yml") || {})
end

#load_classesObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/daily/daily_config.rb', line 56

def load_classes
  Dir[Rails.root.join("app/transforms/**/*.rb")].each { |f| require_dependency f }
  Dir[Rails.root.join("app/formatters/**/*.rb")].each { |f| require_dependency f }
  Dir[Rails.root.join("app/metrics/**/*.rb")].each    { |f| require_dependency f }

  if defined? Daily::Engine
    Dir[Daily::Engine.root.join("app/transforms/**/*.rb")].each { |f| require_dependency f }
    Dir[Daily::Engine.root.join("app/formatters/**/*.rb")].each { |f| require_dependency f }
    Dir[Daily::Engine.root.join("app/metrics/**/*.rb")].each    { |f| require_dependency f }
    Dir[Daily::Engine.root.join("lib/**/*.rb")].each            { |f| require_dependency f }
  end
end

#rails_envObject



16
17
18
19
# File 'lib/daily/daily_config.rb', line 16

def rails_env
  return @env if @env
  Rails.env
end

#rails_rootObject



11
12
13
14
# File 'lib/daily/daily_config.rb', line 11

def rails_root
  return @root if @root
  Rails.root
end

#set_env(env) ⇒ Object



7
8
9
# File 'lib/daily/daily_config.rb', line 7

def set_env(env)
  @env = env
end

#set_root(root) ⇒ Object



4
5
6
# File 'lib/daily/daily_config.rb', line 4

def set_root(root)
  @root = root
end

#subdirectoryObject



29
30
31
32
# File 'lib/daily/daily_config.rb', line 29

def subdirectory
  return "" if rails_env == "test"
  hash['subdirectory'] || env_hash['subdirectory'] || ""
end