Sha256: 2a538279f796872153043e73e96fbc41f0036d861f1439535e9e039c8adccdac

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

module Gritano
  class Config
    def initialize(config_file)
      @config_file = config_file
      load
    end

    def load
      unless File.exist?(@config_file)
        File.open(@config_file, "w").close
      end
      @config = YAML::load(File.open(@config_file))
      unless @config
        @config = Hash.new
      end
    end

    def remove(parameter)
      @config.delete(parameter.to_s)
    end

    def save
      File.open(@config_file, "w") do |f|
        f.write(@config.to_yaml)
      end
    end

    def method_missing(name, *args, &block)
      if name[-1] == '='
        @config[name.to_s[0..-2]] = args[0]
      else
        if @config[name.to_s]
          @config[name.to_s]
        else
          "undefined"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gritano-1.0.0 lib/gritano/config.rb
gritano-0.11.2 lib/gritano/config.rb
gritano-0.11.1 lib/gritano/config.rb