class Stove::Config
Public Instance Methods
__get__(key)
click to toggle source
# File lib/stove/config.rb, line 35 def __get__(key) __raw__[key.to_sym] end
__has__?(key)
click to toggle source
# File lib/stove/config.rb, line 39 def __has__?(key) __raw__.key?(key.to_sym) end
__path__()
click to toggle source
# File lib/stove/config.rb, line 51 def __path__ @path ||= File.expand_path(ENV['STOVE_CONFIG'] || '~/.stove') end
__raw__()
click to toggle source
# File lib/stove/config.rb, line 55 def __raw__ return @__raw__ if @__raw__ @__raw__ = JSON.parse(File.read(__path__), symbolize_names: true) if @__raw__.key?(:community) $stderr.puts "Detected old Stove configuration file, converting..." @__raw__ = { :username => @__raw__[:community][:username], :key => @__raw__[:community][:key], } end @__raw__ rescue Errno::ENOENT => e Stove::Log.warn { "No config file found at `#{__path__}'!" } @__raw__ = {} end
__set__(key, value)
click to toggle source
# File lib/stove/config.rb, line 43 def __set__(key, value) __raw__[key.to_sym] = value end
__unset__(key)
click to toggle source
# File lib/stove/config.rb, line 47 def __unset__(key) __raw__.delete(key.to_sym) end
inspect()
click to toggle source
# File lib/stove/config.rb, line 31 def inspect "#<#{self.class.name} #{__raw__.inspect}>" end
method_missing(m, *args, &block)
click to toggle source
# File lib/stove/config.rb, line 8 def method_missing(m, *args, &block) if m.to_s.end_with?('=') __set__(m.to_s.chomp('='), args.first) else __get__(m) end end
respond_to_missing?(m, include_private = false)
click to toggle source
Calls superclass method
# File lib/stove/config.rb, line 16 def respond_to_missing?(m, include_private = false) __has__?(m) || super end
save()
click to toggle source
# File lib/stove/config.rb, line 20 def save FileUtils.mkdir_p(File.dirname(__path__)) File.open(__path__, 'w') do |f| f.write(JSON.fast_generate(__raw__)) end end
to_s()
click to toggle source
# File lib/stove/config.rb, line 27 def to_s "#<#{self.class.name} #{__raw__.to_s}>" end