Class: Coradoc::Configurable::ConfigSection
- Inherits:
-
Object
- Object
- Coradoc::Configurable::ConfigSection
- Defined in:
- lib/coradoc/configurable.rb
Overview
Base class for configuration sections
Direct Known Subclasses
CacheConfig, LoggingConfig, OutputConfig, ParserConfig, TransformerConfig
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Raw configuration values.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a configuration value.
-
#[]=(key, value) ⇒ Object
Set a configuration value.
-
#initialize(options = {}) ⇒ ConfigSection
constructor
Create a configuration section.
-
#merge!(other) ⇒ void
Merge options into this section.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(options = {}) ⇒ ConfigSection
Create a configuration section
46 47 48 49 |
# File 'lib/coradoc/configurable.rb', line 46 def initialize( = {}) @options = symbolize_keys() after_initialize if respond_to?(:after_initialize) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns Raw configuration values.
35 36 37 |
# File 'lib/coradoc/configurable.rb', line 35 def @options end |
Class Method Details
.symbolize_keys(hash) ⇒ Object
37 38 39 40 41 |
# File 'lib/coradoc/configurable.rb', line 37 def self.symbolize_keys(hash) return {} unless hash.is_a?(Hash) hash.transform_keys(&:to_sym) end |
Instance Method Details
#[](key) ⇒ Object
Get a configuration value
55 56 57 |
# File 'lib/coradoc/configurable.rb', line 55 def [](key) @options[key] end |
#[]=(key, value) ⇒ Object
Set a configuration value
63 64 65 |
# File 'lib/coradoc/configurable.rb', line 63 def []=(key, value) @options[key] = value end |
#merge!(other) ⇒ void
This method returns an undefined value.
Merge options into this section
71 72 73 74 75 76 77 |
# File 'lib/coradoc/configurable.rb', line 71 def merge!(other) = other.is_a?(ConfigSection) ? other. : other = symbolize_keys() @options.merge!() # Apply merged options to accessors () end |
#to_h ⇒ Hash
Convert to hash
82 83 84 85 86 |
# File 'lib/coradoc/configurable.rb', line 82 def to_h @options.transform_values do |v| v.is_a?(ConfigSection) ? v.to_h : v end end |