Sha256: fe9cb9b222c9617b5d6f19ea8c9a2d493f0c6ca3e5974dc0ec0e2fa7819402a9

Contents?: true

Size: 795 Bytes

Versions: 3

Compression:

Stored size: 795 Bytes

Contents

require 'relish/commands/base'
require 'yaml'

module Relish

  # Represents a .relish file
  class OptionsFile

    def initialize(path)
      @path = path
    end
    
    # Store the given options into the file. Existing options with the same keys
    # will be overwritten.
    def store(options)
      @options = self.options.merge(options)
      FileUtils.touch(@path)
      File.open(@path, 'w') do |file|
        YAML.dump(@options, file)
      end
    end
    
    def [](key)
      options[key]
    end
    
    def == (other)
      options == other
    end
    
    # Stored options as a hash
    def options
      @options ||= current_options
    end
    
  private
  
    def current_options
      return {} unless File.exist?(@path)
      YAML.load_file(@path)
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relish-0.1.0 lib/relish/options_file.rb
relish-0.0.9 lib/relish/options_file.rb
relish-0.0.8 lib/relish/options_file.rb