Sha256: 4647f0f9a89f6eeea4c157afd8eb2c793b40dbb41c189aa7a7c0dd12d1db0655

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

class Sinclair
  # 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
    extend ActiveSupport::Concern

    private

    attr_reader :options

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinclair-1.1.2 lib/sinclair/options_parser.rb