Module: Brandish::Processor::PairFilter::ClassMethods

Defined in:
lib/brandish/processor/pair_filter.rb

Overview

The class methods that are implemented on the including module. This is extended onto the class.

Instance Method Summary collapse

Instance Method Details

#allowed_pairs::Set<::String>

A set of allowed pairs that can be used with the command or block element.

Returns:

  • (::Set<::String>)


23
24
25
# File 'lib/brandish/processor/pair_filter.rb', line 23

def allowed_pairs
  @allowed_pairs ||= Set.new
end

#ancestor_allowed_pairs::Set<::String>

A list of all of the ancestors' pairs. This includes the current classes' pairs. This allows allowed pair inheritance.

Returns:

  • (::Set<::String>)


31
32
33
34
35
36
# File 'lib/brandish/processor/pair_filter.rb', line 31

def ancestor_allowed_pairs
  ancestors
    .select { |a| a.respond_to?(:allowed_pairs) }
    .map(&:allowed_pairs)
    .inject(Set.new, :merge)
end

#pairs::Set<::String> #pairs(*pairs) ⇒ void Also known as: pair

Retrives or sets the pairs for the class.

Overloads:

  • #pairs::Set<::String>

    Retrieves the current pairs. This is the same as calling #allowed_pairs.

    Returns:

    • (::Set<::String>)
  • #pairs(*pairs) ⇒ void

    This method returns an undefined value.

    Adds pairs to the current #allowed_pairs.

    Parameters:

    • pairs (::String, ::Symbol, #to_s)


50
51
52
53
# File 'lib/brandish/processor/pair_filter.rb', line 50

def pairs(*pairs)
  return allowed_pairs if pairs.none?
  allowed_pairs.merge(Array(pairs).flatten.map(&:to_s))
end

#unrestricted_pairs!void Also known as: unrestricted_pairs

This method returns an undefined value.

Adds ALL to the pair list, allowing all pairs to be used with the command or block.



60
61
62
# File 'lib/brandish/processor/pair_filter.rb', line 60

def unrestricted_pairs!
  pairs PairFilter::ALL
end