Sha256: a7f9d8fd9b2c4f762ca9e1079464701e75d890e92bef05af82422ef46fd94698

Contents?: true

Size: 979 Bytes

Versions: 10

Compression:

Stored size: 979 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
    extend ActiveSupport::Concern

    private

    # @!visibility public
    attr_reader :options

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sinclair-1.4.1 lib/sinclair/options_parser.rb
sinclair-1.4.0 lib/sinclair/options_parser.rb
sinclair-1.3.4 lib/sinclair/options_parser.rb
sinclair-1.3.3 lib/sinclair/options_parser.rb
sinclair-1.3.2 lib/sinclair/options_parser.rb
sinclair-1.3.1 lib/sinclair/options_parser.rb
sinclair-1.3.0 lib/sinclair/options_parser.rb
sinclair-1.2.1 lib/sinclair/options_parser.rb
sinclair-1.2.0 lib/sinclair/options_parser.rb
sinclair-1.1.3 lib/sinclair/options_parser.rb