class Options::PartialOptions

Partial Options

Class PartialOptions parses the options passed in as partial, then exposes those. Here are the options along with their valid values:

Options may be specified by passing a hash with the option keys:

partial: { match: :from_start, case_sensitive: true }

There are two shortcuts: the partial option can be declared with `true`, which just uses the defaults; or the partial option can be declared with the match option directly, such as partial: :from_start.

Constants

VALID_MATCH_OPTIONS
VALID_OPTIONS

Public Class Methods

new(options) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 21
def initialize(options)
  @match = 'anywhere'
  @case_sensitive = false

  if options.is_a?(TrueClass)
    nil
  elsif options.is_a? Hash
    evaluate_hash(options)
  elsif options.is_a?(String) || options.is_a?(Symbol)
    assign_match(options)
  end
end

Public Instance Methods

case_sensitive?() click to toggle source
# File lib/filterameter/options/partial_options.rb, line 34
def case_sensitive?
  @case_sensitive
end
match_anywhere?() click to toggle source
# File lib/filterameter/options/partial_options.rb, line 38
def match_anywhere?
  @match == 'anywhere'
end
match_dynamically?() click to toggle source
# File lib/filterameter/options/partial_options.rb, line 46
def match_dynamically?
  @match == 'dynamic'
end
match_from_start?() click to toggle source
# File lib/filterameter/options/partial_options.rb, line 42
def match_from_start?
  @match == 'from_start'
end

Private Instance Methods

assign_case_sensitive(value) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 70
def assign_case_sensitive(value)
  validate_case_sensitive(value)
  @case_sensitive = value
end
assign_match(value) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 58
def assign_match(value)
  validate_match(value)
  @match = value.to_s
end
evaluate_hash(options) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 52
def evaluate_hash(options)
  options.assert_valid_keys(:match, :case_sensitive)
  assign_match(options[:match]) if options.key?(:match)
  assign_case_sensitive(options[:case_sensitive]) if options.key?(:case_sensitive)
end
validate_case_sensitive(value) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 75
def validate_case_sensitive(value)
  return if value.is_a?(TrueClass) || value.is_a?(FalseClass)

  raise ArgumentError, "Invalid case_sensitive option for partial: #{value}. Valid options are true and false."
end
validate_match(value) click to toggle source
# File lib/filterameter/options/partial_options.rb, line 63
def validate_match(value)
  return if VALID_MATCH_OPTIONS.include? value.to_s

  raise ArgumentError,
        "Invalid match option for partial: #{value}. Valid options are #{VALID_MATCH_OPTIONS.to_sentence}"
end