Class: Trinidad::Configuration
- Inherits:
-
Object
- Object
- Trinidad::Configuration
- Defined in:
- lib/trinidad/configuration.rb
Overview
Trinidad’s (global) configuration instance. Use Trinidad#configure to update and obtain the global instance or access the instance using Trinidad#configuration
Constant Summary collapse
- DEFAULTS =
{ # :port => 3000, HTTP (depends on connector used) :address => 'localhost', :environment => 'development', :context_path => '/', :public => 'public', :java_lib => 'lib/java', :default_web_xml => 'config/web.xml', :jruby_min_runtimes => java.lang.System.getProperty('jruby.min.runtimes') || 1, :jruby_max_runtimes => java.lang.System.getProperty('jruby.max.runtimes') || 5, :log => 'INFO', :trap => true }
Class Method Summary collapse
-
.merge_options(target, current, deep = true) ⇒ Object
a Hash like deep_merge helper.
-
.symbolize_options(options, deep = true) ⇒ Object
a Hash like #symbolize helper.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #each(&block) ⇒ Object
- #has_key?(name) ⇒ Boolean (also: #key?)
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #keys ⇒ Object
- #update!(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
51 52 53 54 |
# File 'lib/trinidad/configuration.rb', line 51 def initialize( = {}) @config = DEFAULTS.clone update!() end |
Class Method Details
.merge_options(target, current, deep = true) ⇒ Object
a Hash like deep_merge helper
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/trinidad/configuration.rb', line 114 def self.(target, current, deep = true) return target unless current target_dup = target.dup current.keys.each do |key| target_dup[key] = if deep && (target[key]) && (current[key]) (target[key], current[key], deep) else current[key] end end target_dup end |
.symbolize_options(options, deep = true) ⇒ Object
a Hash like #symbolize helper
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/trinidad/configuration.rb', line 96 def self.(, deep = true) = .class.new .each do |key, value| if deep && value.is_a?(Array) # YAML::Omap is an Array array = [key.to_sym] = value.class.new value.each do |v| array << ( (v) ? (v, deep) : v ) end elsif deep && (value) [key.to_sym] = (value, deep) else [key.to_sym] = value end end end |
Instance Method Details
#[](name) ⇒ Object
56 57 58 |
# File 'lib/trinidad/configuration.rb', line 56 def [](name) @config[name.to_sym] end |
#[]=(name, value) ⇒ Object
60 61 62 |
# File 'lib/trinidad/configuration.rb', line 60 def []=(name, value) @config[name.to_sym] = value end |
#each(&block) ⇒ Object
73 74 75 |
# File 'lib/trinidad/configuration.rb', line 73 def each(&block) @config.each(&block) end |
#has_key?(name) ⇒ Boolean Also known as: key?
64 65 66 |
# File 'lib/trinidad/configuration.rb', line 64 def has_key?(name) @config.has_key?(name.to_sym) end |
#keys ⇒ Object
69 70 71 |
# File 'lib/trinidad/configuration.rb', line 69 def keys @config.keys end |
#update!(options) ⇒ Object
77 78 79 80 81 |
# File 'lib/trinidad/configuration.rb', line 77 def update!() .each do |key, value| self[key] = value.respond_to?(:strip) ? value.strip : value end end |