Sha256: d05f3d24a0ead282bd33d7bce6a02636ac81e5bd43bb4d2dc63acc728ba1c3a8

Contents?: true

Size: 768 Bytes

Versions: 6

Compression:

Stored size: 768 Bytes

Contents

module Redistat
  module Options
    
    def self.included(base)
      base.extend(ClassMethods)
    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

6 entries across 6 versions & 1 rubygems

Version Path
redistat-0.3.0 lib/redistat/mixins/options.rb
redistat-0.2.6 lib/redistat/options.rb
redistat-0.2.5 lib/redistat/options.rb
redistat-0.2.4 lib/redistat/options.rb
redistat-0.2.3 lib/redistat/options.rb
redistat-0.2.2 lib/redistat/options.rb