Sha256: 013057a6077b6fcc6ecb705cee4709366ca3eb90bc4aff6b5485b393605d1f6a

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

class Sinclair
  # @api public
  #
  # @author darthjee
  #
  # Concern for easily adding options
  #
  # @example
  #   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
  module OptionsParser
    private

    # @attr_reader options
    # @!visibility public
    # @private
    #
    # Options hash
    #
    # @return [Hash]
    attr_reader :options

    # @!visibility public
    # @api public
    #
    # Builds an openstruct of the Hash
    #
    # @return [OpenStruct]
    def options_object
      @options_object ||= OpenStruct.new options
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/options_parser.rb
sinclair-2.1.0 lib/sinclair/options_parser.rb
sinclair-2.0.1 lib/sinclair/options_parser.rb
sinclair-2.0.0 lib/sinclair/options_parser.rb
sinclair-1.16.3 lib/sinclair/options_parser.rb
sinclair-1.16.2 lib/sinclair/options_parser.rb