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
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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/trinidad/configuration.rb', line 35 def initialize( = {}) @config = { :port => 3000, :address => 'localhost', :environment => 'development', :context_path => '/', :libs_dir => 'lib', :classes_dir => 'classes', :default_web_xml => 'config/web.xml', :jruby_min_runtimes => 1, :jruby_max_runtimes => 5, :log => 'INFO', :trap => true } update!() end |
Class Method Details
.merge_options(target, current, deep = true) ⇒ Object
a Hash like deep_merge helper
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/trinidad/configuration.rb', line 109 def self.(target, current, deep = true) 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/trinidad/configuration.rb', line 91 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
52 53 54 |
# File 'lib/trinidad/configuration.rb', line 52 def [](name) @config[name.to_sym] end |
#[]=(name, value) ⇒ Object
56 57 58 |
# File 'lib/trinidad/configuration.rb', line 56 def []=(name, value) @config[name.to_sym] = value end |
#each(&block) ⇒ Object
69 70 71 |
# File 'lib/trinidad/configuration.rb', line 69 def each(&block) @config.each(&block) end |
#has_key?(name) ⇒ Boolean Also known as: key?
60 61 62 |
# File 'lib/trinidad/configuration.rb', line 60 def has_key?(name) @config.has_key?(name.to_sym) end |
#keys ⇒ Object
65 66 67 |
# File 'lib/trinidad/configuration.rb', line 65 def keys @config.keys end |
#update!(options) ⇒ Object
73 74 75 76 77 |
# File 'lib/trinidad/configuration.rb', line 73 def update!() .each do |key, value| self[key] = value.respond_to?(:strip) ? value.strip : value end end |