Class: Shitcan::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
8
# File 'lib/shitcan/config.rb', line 5

def initialize(opts={})
  @app_root = opts[:app_root]  || RAILS_ROOT
  @env      = opts[:rails_env] || RAILS_ENV   || 'development'
end

Instance Attribute Details

#app_rootObject

Returns the value of attribute app_root.



3
4
5
# File 'lib/shitcan/config.rb', line 3

def app_root
  @app_root
end

#envObject

Returns the value of attribute env.



3
4
5
# File 'lib/shitcan/config.rb', line 3

def env
  @env
end

Instance Method Details

#cacheObject



21
22
23
# File 'lib/shitcan/config.rb', line 21

def cache
  @cache ||= Memcached.new(memcache_conf)
end

#memcache_confObject



10
11
12
13
# File 'lib/shitcan/config.rb', line 10

def memcache_conf
  path = "#{app_root}/config/memcache.yml"
  @memcache_conf ||= File.exists?(path) ? YAML::load(ERB.new(IO.read(path)).result)[env] : 'localhost:11211'
end

#shitcan_confObject

TODO: Think up some custom configuration options



16
17
18
19
# File 'lib/shitcan/config.rb', line 16

def shitcan_conf
  path = "#{app_root}/config/shitcan.yml"
  @shitcan_conf ||= YAML::load(ERB.new(IO.read(path)).result)[env]
end