Class: FReCon::Configuration

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Configuration

Returns a new instance of Configuration.



14
15
16
17
18
# File 'lib/frecon/configuration.rb', line 14

def initialize(data)
	data.each do |key, value|
		self[key] = value
	end
end

Class Method Details

.construct!(default_configuration: ConfigurationFile.default.read, system_configuration: ConfigurationFile.system.read, user_configuration: ConfigurationFile.user.read, argument_configuration: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/frecon/configuration.rb', line 52

def self.construct!(default_configuration: ConfigurationFile.default.read,
                    system_configuration: ConfigurationFile.system.read,
                    user_configuration: ConfigurationFile.user.read,
                    argument_configuration: nil)

	configuration_hierarchy = [default_configuration, system_configuration, user_configuration, argument_configuration]

	configuration = Configuration.new({})
	configuration_hierarchy.each do |other_configuration|
		configuration.merge(other_configuration)
	end

	configuration
end

Instance Method Details

#merge(other) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/frecon/configuration.rb', line 35

def merge(other)
	case other
	when Configuration, Hash
		other.each do |key, value|
			case value
			when Configuration, Hash
				me = Configuration.new(self[key] || {})
				me.merge(Configuration.new(value))
				self[key] = me
			else
				self[key] = value
			end
		end
	when nil
	end
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/frecon/configuration.rb', line 20

def to_h
	hash = {}

	self.each do |key, value|
		case value
		when Configuration
			hash[key] = value.to_h
		else
			hash[key] = value
		end
	end

	hash
end