Class: Rad::Config
Constant Summary collapse
- DEFAULTS =
{}
- RUNTIME =
{}
Instance Attribute Summary collapse
Instance Method Summary collapse
- #development(&block) ⇒ Object
- #development? ⇒ Boolean
-
#environment=(env) ⇒ Object
environment.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#merge_config!(file_path) ⇒ Object
trying to load both file_path and file_path.environment files if they are exists.
- #production(&block) ⇒ Object
- #production? ⇒ Boolean
-
#public_dir ⇒ Object
public_dir.
- #public_dir! ⇒ Object
- #public_dir? ⇒ Boolean
-
#runtime_dir=(runtime_dir) ⇒ Object
runtime_dir.
- #test(&block) ⇒ Object
- #test? ⇒ Boolean
Constructor Details
Instance Attribute Details
#log_level ⇒ Object
92 93 94 |
# File 'lib/rad/environment/config.rb', line 92 def log_level @log_level ||= production? ? :info : :debug end |
#log_path ⇒ Object
83 84 85 |
# File 'lib/rad/environment/config.rb', line 83 def log_path @log_path ||= runtime_dir? ? "#{runtime_dir}/log/#{environment}.log" : "" end |
Instance Method Details
#development(&block) ⇒ Object
75 |
# File 'lib/rad/environment/config.rb', line 75 def development █ block.call if development? end |
#development? ⇒ Boolean
71 |
# File 'lib/rad/environment/config.rb', line 71 def development?; environment == 'development' end |
#environment=(env) ⇒ Object
environment
65 66 67 68 69 |
# File 'lib/rad/environment/config.rb', line 65 def environment= env env = env.to_s env.must_be.in %w{production development test} self['environment'] = env end |
#merge_config!(file_path) ⇒ Object
trying to load both file_path and file_path.environment files if they are exists
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rad/environment/config.rb', line 16 def merge_config! file_path # unless ::Micon.include? :config # raise("this method should be called only after config already initialized (use app.after :config do ... end)!") # end raise("config file must have .yml extension (#{file_path})!") unless file_path.end_with? '.yml' default_file_path = file_path.sub(/yml$/, "default.yml") file_path_for_current_environment = file_path.sub(/yml$/, "#{environment!}.yml") [ default_file_path, file_path, file_path_for_current_environment ].each do |cfile| if ::File.exist? cfile data = ::YAML.load_file cfile if data data.must_be.a ::Hash self.deep_merge! data end end end end |
#production(&block) ⇒ Object
76 |
# File 'lib/rad/environment/config.rb', line 76 def production █ block.call if production? end |
#production? ⇒ Boolean
72 |
# File 'lib/rad/environment/config.rb', line 72 def production?; environment == 'production' end |
#public_dir ⇒ Object
public_dir
53 54 55 |
# File 'lib/rad/environment/config.rb', line 53 def public_dir runtime_dir? ? "#{runtime_dir}/public" : self[:public_dir] end |
#public_dir! ⇒ Object
57 58 59 |
# File 'lib/rad/environment/config.rb', line 57 def public_dir! "#{runtime_dir!}/public" end |
#public_dir? ⇒ Boolean
56 |
# File 'lib/rad/environment/config.rb', line 56 def public_dir?; runtime_dir? end |
#runtime_dir=(runtime_dir) ⇒ Object
runtime_dir
41 42 43 44 45 46 47 |
# File 'lib/rad/environment/config.rb', line 41 def runtime_dir= runtime_dir if runtime_dir self[:runtime_dir] = ::File.(runtime_dir) else self.delete 'runtime_dir' end end |
#test(&block) ⇒ Object
77 |
# File 'lib/rad/environment/config.rb', line 77 def test █ block.call if test? end |
#test? ⇒ Boolean
73 |
# File 'lib/rad/environment/config.rb', line 73 def test?; environment == 'test' end |