Class: Coradoc::Configurable::ConfigSection

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/configurable.rb

Overview

Base class for configuration sections

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ConfigSection

Create a configuration section

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options



46
47
48
49
# File 'lib/coradoc/configurable.rb', line 46

def initialize(options = {})
  @options = symbolize_keys(options)
  after_initialize if respond_to?(:after_initialize)
end

Instance Attribute Details

#optionsHash (readonly)

Returns Raw configuration values.

Returns:

  • (Hash)

    Raw configuration values



35
36
37
# File 'lib/coradoc/configurable.rb', line 35

def options
  @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

Parameters:

  • key (Symbol)

    Configuration key

Returns:

  • (Object)

    Configuration value



55
56
57
# File 'lib/coradoc/configurable.rb', line 55

def [](key)
  @options[key]
end

#[]=(key, value) ⇒ Object

Set a configuration value

Parameters:

  • key (Symbol)

    Configuration key

  • value (Object)

    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

Parameters:



71
72
73
74
75
76
77
# File 'lib/coradoc/configurable.rb', line 71

def merge!(other)
  other_options = other.is_a?(ConfigSection) ? other.options : other
  other_options = symbolize_keys(other_options)
  @options.merge!(other_options)
  # Apply merged options to accessors
  apply_options(other_options)
end

#to_hHash

Convert to hash

Returns:

  • (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