Sha256: 499887725eaeddc96e363e11b0e4f6dec41403b713715bb7118c2c2bc61785ca

Contents?: true

Size: 1014 Bytes

Versions: 23

Compression:

Stored size: 1014 Bytes

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

    # @!visibility public
    #
    # 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

23 entries across 23 versions & 1 rubygems

Version Path
sinclair-1.16.1 lib/sinclair/options_parser.rb
sinclair-1.16.0 lib/sinclair/options_parser.rb
sinclair-1.15.0 lib/sinclair/options_parser.rb
sinclair-1.14.2 lib/sinclair/options_parser.rb
sinclair-1.14.1 lib/sinclair/options_parser.rb
sinclair-1.14.0 lib/sinclair/options_parser.rb
sinclair-1.13.0 lib/sinclair/options_parser.rb
sinclair-1.12.1 lib/sinclair/options_parser.rb
sinclair-1.12.0 lib/sinclair/options_parser.rb
sinclair-1.11.0 lib/sinclair/options_parser.rb
sinclair-1.10.0 lib/sinclair/options_parser.rb
sinclair-1.9.0 lib/sinclair/options_parser.rb
sinclair-1.8.0 lib/sinclair/options_parser.rb
sinclair-1.7.0 lib/sinclair/options_parser.rb
sinclair-1.6.7 lib/sinclair/options_parser.rb
sinclair-1.6.6 lib/sinclair/options_parser.rb
sinclair-1.6.5 lib/sinclair/options_parser.rb
sinclair-1.6.4 lib/sinclair/options_parser.rb
sinclair-1.6.3 lib/sinclair/options_parser.rb
sinclair-1.6.2 lib/sinclair/options_parser.rb