Class: DiscourseTheme::Config
- Inherits:
-
Object
- Object
- DiscourseTheme::Config
- Defined in:
- lib/discourse_theme/config.rb
Defined Under Namespace
Classes: PathSetting
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#raw_config ⇒ Object
readonly
Returns the value of attribute raw_config.
Instance Method Summary collapse
- #[](path) ⇒ Object
-
#initialize(filename) ⇒ Config
constructor
A new instance of Config.
- #save ⇒ Object
Constructor Details
#initialize(filename) ⇒ Config
Returns a new instance of Config.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/discourse_theme/config.rb', line 93 def initialize(filename) @filename = filename if File.exist?(@filename) begin @raw_config = YAML.load_file(@filename) raise unless Hash === @raw_config rescue StandardError @raw_config = {} $stderr.puts "ERROR: #{@filename} contains invalid config, resetting" end else @raw_config = {} end end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
91 92 93 |
# File 'lib/discourse_theme/config.rb', line 91 def filename @filename end |
#raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
91 92 93 |
# File 'lib/discourse_theme/config.rb', line 91 def raw_config @raw_config end |
Instance Method Details
#[](path) ⇒ Object
113 114 115 |
# File 'lib/discourse_theme/config.rb', line 113 def [](path) PathSetting.new(self, path) end |
#save ⇒ Object
109 110 111 |
# File 'lib/discourse_theme/config.rb', line 109 def save File.write(@filename, @raw_config.to_yaml) end |