Class: Cogwheels::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cogwheels/configuration.rb

Overview

This class contains configuration information loaded from YAML sources

Defined Under Namespace

Classes: ImmutableConfigurationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, mutable = true) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/cogwheels/configuration.rb', line 9

def initialize(hash, mutable = true)
  @hash = hash
  @mutable = mutable
end

Instance Attribute Details

#mutableObject (readonly)

Returns the value of attribute mutable.



7
8
9
# File 'lib/cogwheels/configuration.rb', line 7

def mutable
  @mutable
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/cogwheels/configuration.rb', line 14

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

#[]=(key, value) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/cogwheels/configuration.rb', line 18

def []=(key, value)
  unless @mutable
    error = <<-EOF
A modification was attempted on an immutable Configuration instance.
  EOF
    raise ImmutableConfigurationError, error
  end
  @hash[key] = value if @mutable
end

#inspectObject



32
33
34
# File 'lib/cogwheels/configuration.rb', line 32

def inspect
  "Cogwheels::Configuration =>\n#{@hash}"
end

#to_sObject



28
29
30
# File 'lib/cogwheels/configuration.rb', line 28

def to_s
  @hash.to_s
end