Class: GemConfig::Configuration

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

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Configuration

Returns a new instance of Configuration.



3
4
5
# File 'lib/gem_config/configuration.rb', line 3

def initialize(parent = nil)
  @parent = parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/gem_config/configuration.rb', line 29

def method_missing(method, *args, &block)
  case
  when self.rules.keys.include?(method.to_sym)
    get method
  when (match = method.to_s.match(/\A(?<key>\w+)=\z/)) && self.rules.keys.include?(match[:key].to_sym)
    set match[:key], args.first
  else
    super
  end
end

Instance Method Details

#currentObject



11
12
13
14
15
# File 'lib/gem_config/configuration.rb', line 11

def current
  self.rules.keys.each_with_object({}) do |key, hash|
    hash[key] = get(key)
  end
end

#resetObject



17
18
19
20
21
# File 'lib/gem_config/configuration.rb', line 17

def reset
  self.rules.keys.each do |key|
    unset key
  end
end

#rulesObject



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

def rules
  @rules ||= Rules.new
end

#unset(key) ⇒ Object

Raises:



23
24
25
26
27
# File 'lib/gem_config/configuration.rb', line 23

def unset(key)
  raise InvalidKeyError, "#{key} is not a valid key." unless self.rules.keys.include?(key.to_sym)
  remove_instance_variable "@#{key}" if instance_variable_defined?("@#{key}")
  call_after_configuration_change
end