Class: Appydave::Tools::Configuration::Models::ConfigBase
- Inherits:
-
Object
- Object
- Appydave::Tools::Configuration::Models::ConfigBase
show all
- Includes:
- KLog::Logging
- Defined in:
- lib/appydave/tools/configuration/models/config_base.rb
Overview
Base class for handling common configuration tasks
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ConfigBase.
16
17
18
19
20
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 16
def initialize
@config_path = File.join(Config.config_path, "#{config_name}.json")
@data = load
end
|
Instance Attribute Details
#config_path ⇒ Object
Returns the value of attribute config_path.
14
15
16
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 14
def config_path
@config_path
end
|
#data ⇒ Object
Returns the value of attribute data.
14
15
16
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 14
def data
@data
end
|
Instance Method Details
#config_name ⇒ Object
39
40
41
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 39
def config_name
name.gsub(/([a-z])([A-Z])/, '\1-\2').downcase
end
|
#debug ⇒ Object
43
44
45
46
47
48
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 43
def debug
log.kv 'Config', name
log.kv 'Path', config_path
log.json data
end
|
#load ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 26
def load
return JSON.parse(File.read(config_path)) if File.exist?(config_path)
default_data
rescue JSON::ParserError
default_data
end
|
#name ⇒ Object
35
36
37
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 35
def name
self.class.name.split('::')[-1].gsub(/Config$/, '')
end
|
#save ⇒ Object
22
23
24
|
# File 'lib/appydave/tools/configuration/models/config_base.rb', line 22
def save
File.write(config_path, JSON.pretty_generate(data))
end
|