Sha256: 9940e7057829908b01de3e89dbe84a6dc5fa6288f156c62e10bad5f4720676ae

Contents?: true

Size: 757 Bytes

Versions: 6

Compression:

Stored size: 757 Bytes

Contents

require "yaml"
require "singleton"

module GetToWork
  class ConfigFile
    attr_reader :data
    include Singleton

    def initialize
      setup_data(self.class.path)
    end

    def setup_data(path)
      @data = begin
                YAML.load_file(path)
              rescue Errno::ENOENT
                {}
              end
    end

    def [](key)
      @data[key]
    end

    def []=(key, value)
      @data[key] = value
    end

    def self.save
      instance.save
    end

    def save
      File.open(self.class.path, "w") { |f| f.write YAML.dump(@data) }
    end

    def self.exist?
      File.exist? path
    end

    def self.path
      File.join(Dir.pwd, filename)
    end

    def self.filename
      ".get-to-work"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
get_to_work-0.1.5 lib/get_to_work/config_file.rb
get_to_work-0.1.4 lib/get_to_work/config_file.rb
get_to_work-0.1.3 lib/get_to_work/config_file.rb
get_to_work-0.1.2 lib/get_to_work/config_file.rb
get_to_work-0.1.1 lib/get_to_work/config_file.rb
get_to_work-0.1.0 lib/get_to_work/config_file.rb