Sha256: a6df84fc1875ed4ec1d887e18acf6a60162a5e19e8935390f116dd4790ba0b0d

Contents?: true

Size: 864 Bytes

Versions: 20

Compression:

Stored size: 864 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
    
    def merge(other)
      options.merge(other.options)
    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

20 entries across 20 versions & 1 rubygems

Version Path
relish-0.7.1 lib/relish/options_file.rb
relish-0.7 lib/relish/options_file.rb
relish-0.6 lib/relish/options_file.rb
relish-0.5.3 lib/relish/options_file.rb
relish-0.5.2 lib/relish/options_file.rb
relish-0.5.1 lib/relish/options_file.rb
relish-0.5.0 lib/relish/options_file.rb
relish-0.4.0 lib/relish/options_file.rb
relish-0.3.0 lib/relish/options_file.rb
relish-0.3.0.pre lib/relish/options_file.rb
relish-0.2.3 lib/relish/options_file.rb
relish-0.2.2 lib/relish/options_file.rb
relish-0.2.1 lib/relish/options_file.rb
relish-0.2.0 lib/relish/options_file.rb
relish-0.1.6 lib/relish/options_file.rb
relish-0.1.5 lib/relish/options_file.rb
relish-0.1.4 lib/relish/options_file.rb
relish-0.1.3 lib/relish/options_file.rb
relish-0.1.2 lib/relish/options_file.rb
relish-0.1.1 lib/relish/options_file.rb