class Ironment::Config
Attributes
config_path[W]
Public Class Methods
config_path()
click to toggle source
# File lib/ironment/config.rb, line 17 def config_path @config_path || default_config_path end
default_config_path()
click to toggle source
# File lib/ironment/config.rb, line 21 def default_config_path File.join(Dir.home, ".config", "ironment", "config") end
Public Instance Methods
[](key)
click to toggle source
# File lib/ironment/config.rb, line 26 def [](key) read_pairs[key] end
[]=(key, value)
click to toggle source
# File lib/ironment/config.rb, line 30 def []=(key, value) if value.nil? write_pairs read_pairs.except(key) else write_pairs read_pairs.merge(key => value) end end
Private Instance Methods
file()
click to toggle source
# File lib/ironment/config.rb, line 60 def file self.class.config_path end
read_pairs()
click to toggle source
# File lib/ironment/config.rb, line 40 def read_pairs if File.exist?(file) Hash[*File.read(file).split(/\n/).map { |line| line.split(/=/) }.flatten] else {} end end
write_pairs(pairs)
click to toggle source
# File lib/ironment/config.rb, line 50 def write_pairs(pairs) dir = Pathname.new(file).dirname unless dir.exist? dir.mkpath end File.write(file, pairs.map { |k, v| "#{k}=#{v}" }.join("\n")) end