Class: AppConfig
- Inherits:
-
Object
- Object
- AppConfig
- Defined in:
- app/base/base/config.rb
Constant Summary collapse
- ENVIRONMENTS =
[:development, :test, :production].freeze
- DEFAULT_ENV =
ENVIRONMENTS.first
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](config) ⇒ Object
reading configs set into config.yml or programmatically(via Cfg = ‘bar’).
-
#[]=(key, val) ⇒ Object
allow to set custom configs without write them into config.yml.
- #development? ⇒ Boolean (also: #dev?)
-
#initialize ⇒ AppConfig
constructor
A new instance of AppConfig.
- #production? ⇒ Boolean (also: #prod?)
-
#root_path(*chunks) ⇒ Object
full path to application root, ie.
- #test? ⇒ Boolean
Constructor Details
#initialize ⇒ AppConfig
Returns a new instance of AppConfig.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/base/base/config.rb', line 8 def initialize @env = (ENV['RACK_ENV'] || DEFAULT_ENV).to_s.to_sym ENVIRONMENTS.include?(@env) || raise("#{@env} environment not supported. Please use one of #{ENVIRONMENTS*', '}") @env_map = ENVIRONMENTS.inject({}) {|map,e| map.merge(e => e == env)}.freeze set_paths Dir.pwd set_env env load_config load_db_config @opted_config = {} end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
6 7 8 |
# File 'app/base/base/config.rb', line 6 def db @db end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'app/base/base/config.rb', line 6 def env @env end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'app/base/base/config.rb', line 6 def path @path end |
Class Method Details
.paths ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/base/base/config.rb', line 20 def self.paths { root: [:config, :base, :public, :var, :tmp], base: [:models, :views, :controllers, :helpers, :specs, :migrations], var: [:pid, :log], public: [:assets], } end |
Instance Method Details
#[](config) ⇒ Object
reading configs set into config.yml or programmatically(via Cfg = ‘bar’)
56 57 58 |
# File 'app/base/base/config.rb', line 56 def [] config @config[config] || @opted_config[config] end |
#[]=(key, val) ⇒ Object
allow to set custom configs without write them into config.yml
51 52 53 |
# File 'app/base/base/config.rb', line 51 def []= key, val @opted_config[key] = val end |
#development? ⇒ Boolean Also known as: dev?
60 61 62 |
# File 'app/base/base/config.rb', line 60 def development? @env_map[:development] end |
#production? ⇒ Boolean Also known as: prod?
65 66 67 |
# File 'app/base/base/config.rb', line 65 def production? @env_map[:production] end |
#root_path(*chunks) ⇒ Object
full path to application root, ie. the folder containing base/ public/ var/ etc.
31 32 33 |
# File 'app/base/base/config.rb', line 31 def root_path *chunks File.join(@path[:root], *chunks.map(&:to_s)) end |
#test? ⇒ Boolean
70 71 72 |
# File 'app/base/base/config.rb', line 70 def test? @env_map[:test] end |