Sha256: 82ad0fab687d6f0764cef3aca4f00c6e2ac48a0a513968febac25f2001d3db56

Contents?: true

Size: 557 Bytes

Versions: 5

Compression:

Stored size: 557 Bytes

Contents

# frozen_string_literal: true

module OptionsParser
  def required_options(initializer)
    options_that_are(initializer, :required)
  end

  def optional_options(initializer)
    options_that_are(initializer, :optional)
  end

  private

  def options_that_are(initializer, constraint)
    raise(ArgumentError, 'constraint must be required or optional') unless %i[required optional].include?(constraint)

    method = constraint.eql?(:required) ? :select : :reject
    initializer[2][:current_command].options.send(method) { |_k, v| v.required }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
emasser-3.4.0 lib/emasser/options_parser.rb
emasser-1.0.6 lib/emasser/options_parser.rb
emasser-1.0.3 lib/emasser/options_parser.rb
emasser-1.0.1 lib/emasser/options_parser.rb
emasser-1.0.0 lib/emasser/options_parser.rb