Sha256: 4be4f0806897f064b3f9c2017673f2cc011e4a267ea02f711a007acf41838f71

Contents?: true

Size: 826 Bytes

Versions: 2

Compression:

Stored size: 826 Bytes

Contents

module Redistat
  module Options
    
    def self.included(base)
      base.extend(ClassMethods)
    end
    
    class InvalidDefaultOptions < ArgumentError; end
    
    module ClassMethods
      def option_accessor(*opts)
        opts.each do |option|
          define_method(option) do |*args|
            if !args.first.nil?
              options[option.to_sym] = args.first
            else
              options[option.to_sym] || nil
            end
          end
        end
      end
    end
    
    def parse_options(opts)
      opts ||= {}
      @raw_options = opts
      @options = default_options.merge(opts.reject { |k,v| v.nil? })
    end
    
    def default_options
      {}
    end
    
    def options
      @options ||= {}
    end
    
    def raw_options
      @raw_options ||= {}
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redistat-0.2.1 lib/redistat/options.rb
redistat-0.2.0 lib/redistat/options.rb