Class: DiscourseTheme::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/discourse_theme/config.rb

Defined Under Namespace

Classes: PathSetting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Config

Returns a new instance of Config.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/discourse_theme/config.rb', line 74

def initialize(filename)
  @filename = filename

  if File.exist?(@filename)
    begin
      @raw_config = YAML.load_file(@filename)
      raise unless Hash === @raw_config
    rescue
      @raw_config = {}
      $stderr.puts "ERROR: #{@filename} contains invalid config, resetting"
    end
  else
    @raw_config = {}
  end
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



72
73
74
# File 'lib/discourse_theme/config.rb', line 72

def filename
  @filename
end

#raw_configObject (readonly)

Returns the value of attribute raw_config.



72
73
74
# File 'lib/discourse_theme/config.rb', line 72

def raw_config
  @raw_config
end

Instance Method Details

#[](path) ⇒ Object



94
95
96
# File 'lib/discourse_theme/config.rb', line 94

def [](path)
  PathSetting.new(self, path)
end

#saveObject



90
91
92
# File 'lib/discourse_theme/config.rb', line 90

def save
  File.write(@filename, @raw_config.to_yaml)
end