Sha256: 3ecc27e6cd1a85a0e9ca7b7e41ea28214e9610f47eec724dd887d593f1cbbdef

Contents?: true

Size: 801 Bytes

Versions: 2

Compression:

Stored size: 801 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)
      new_options = self.options.merge(options)
      FileUtils.touch(@path)
      File.open(@path, 'w') do |file|
        YAML.dump(new_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

2 entries across 2 versions & 1 rubygems

Version Path
relish-0.0.7 lib/relish/options_file.rb
relish-0.0.6 lib/relish/options_file.rb