Module: Sinclair::OptionsParser

Extended by:
ActiveSupport::Concern
Included in:
Sinclair, MethodDefinition
Defined in:
lib/sinclair/options_parser.rb

Overview

Concern for easily adding options

Examples:

class Sinclair
  class OptionsParser::Dummy
    include OptionsParser

    def initialize(options)
      @options = options.deep_dup
    end
  end

  def the_method
    return 'missing option' if options_object.switch.nil?

    if options_object.switch
      "The value is #{options_object.option_1}"
    else
      "The value is not #{options_object.option_1} but #{options_object.option_2}"
    end
  end
end

Author:

  • darthjee

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)



36
37
38
# File 'lib/sinclair/options_parser.rb', line 36

def options
  @options
end

Instance Method Details

#options_objectOpenStruct

Builds an openstruct of the Hash

Returns:

  • (OpenStruct)


43
44
45
# File 'lib/sinclair/options_parser.rb', line 43

def options_object
  @options_object ||= OpenStruct.new options
end