Sha256: 3f5f85fc3b57ef17db2f360d1779c74336ffac8d28e81473c589b135bfb869f6

Contents?: true

Size: 761 Bytes

Versions: 3

Compression:

Stored size: 761 Bytes

Contents

module Bowline
  class AppConfig
    attr_reader :keys, :path
    def initialize(path)
      @path = path
      @keys = {}
      load!
    end
    
    def load!
      return unless File.exist?(path)
      @keys = YAML::load(File.read(path))
    end
    
    def dump!
      File.open(path, "w+") {|f| f.write(YAML::dump(keys)) }
    end
    
    def delete(key)
      @keys.delete(key)
      dump!
    end
    
    def method_missing(sym, *args)
      method_name = sym.to_s
      
      if method_name =~ /(=|\?)$/
        case $1
        when "="
          keys[$`] = args.first
          dump!
        when "?"
          keys[$`]
        end
      else
        return keys[method_name] if keys.include?(method_name)
        super
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bowline-0.6.2 lib/bowline/app_config.rb
bowline-0.6.1 lib/bowline/app_config.rb
bowline-0.6.0 lib/bowline/app_config.rb