Class: Tumugi::Config
- Inherits:
-
Object
- Object
- Tumugi::Config
- Defined in:
- lib/tumugi/config.rb
Instance Attribute Summary collapse
-
#max_retry ⇒ Object
Returns the value of attribute max_retry.
-
#param_auto_bind_enabled ⇒ Object
Returns the value of attribute param_auto_bind_enabled.
-
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
-
#workers ⇒ Object
Returns the value of attribute workers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #section(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
22 23 24 25 26 27 28 29 |
# File 'lib/tumugi/config.rb', line 22 def initialize @workers = 1 @max_retry = 3 @retry_interval = 300 #seconds @param_auto_bind_enabled = true @section_procs = {} @section_instances = {} end |
Instance Attribute Details
#max_retry ⇒ Object
Returns the value of attribute max_retry.
6 7 8 |
# File 'lib/tumugi/config.rb', line 6 def max_retry @max_retry end |
#param_auto_bind_enabled ⇒ Object
Returns the value of attribute param_auto_bind_enabled.
6 7 8 |
# File 'lib/tumugi/config.rb', line 6 def param_auto_bind_enabled @param_auto_bind_enabled end |
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
6 7 8 |
# File 'lib/tumugi/config.rb', line 6 def retry_interval @retry_interval end |
#workers ⇒ Object
Returns the value of attribute workers.
6 7 8 |
# File 'lib/tumugi/config.rb', line 6 def workers @workers end |
Class Method Details
.camelize(term) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/tumugi/config.rb', line 15 def self.camelize(term) string = term.to_s string = string.sub(/^[a-z\d]*/) { $&.capitalize } string.gsub!(/(?:_|(\/))([a-z\d]*)/) { $2.capitalize } string end |
Instance Method Details
#section(name, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tumugi/config.rb', line 31 def section(name, &block) section_class = @@sections[name] if block_given? @section_procs[name] ||= block elsif section_class.nil? raise ConfigError, "Config section '#{name}' is not registered." else @section_instances[name] ||= section_class.new if @section_procs[name] begin @section_procs[name].call(@section_instances[name]) rescue NoMethodError => e Tumugi.logger.error "#{e.}. Available attributes are #{@section_instances[name].members}" raise e end end @section_instances[name] end end |