Module: Might::FilterPredicates

Defined in:
lib/might/filter_predicates.rb

Overview

Contains contains with all supported predicates You can register your own predicates. Predicates should perform on array or on singular value:

Might::FilterPredicates.register('includes', on: :array)
Might::FilterPredicates.register('is_upper_case', on: :value)

Constant Summary collapse

NOT_EQ =
'not_eq'.freeze
EQ =
'eq'.freeze
DOES_NOT_MATCH =
'does_not_match'.freeze
MATCHES =
'matches'.freeze
GT =
'gt'.freeze
LT =
'lt'.freeze
GTEQ =
'gteq'.freeze
LTEQ =
'lteq'.freeze
NOT_CONT =
'not_cont'.freeze
CONT =
'cont'.freeze
NOT_START =
'not_start'.freeze
START =
'start'.freeze
DOES_NOT_END =
'not_end'.freeze
ENDS =
'end'.freeze
NOT_TRUE =
'not_true'.freeze
TRUE =
'true'.freeze
NOT_FALSE =
'not_false'.freeze
FALSE =
'false'.freeze
BLANK =
'blank'.freeze
PRESENT =
'present'.freeze
NOT_NULL =
'not_null'.freeze
NULL =
'null'.freeze
NOT_IN =
'not_in'.freeze
IN =
'in'.freeze
NOT_CONT_ANY =
'not_cont_any'.freeze
CONT_ANY =
'cont_any'.freeze

Class Method Summary collapse

Class Method Details

.allSet<String>

Returns all predicates

Returns:

  • (Set<String>)


91
92
93
# File 'lib/might/filter_predicates.rb', line 91

def all
  @predicates_on_value + @predicates_on_array
end

.arraySet<String>

Returns predicates for array

Returns:

  • (Set<String>)


75
76
77
# File 'lib/might/filter_predicates.rb', line 75

def array
  @predicates_on_array.dup
end

.register(predicate, on:) ⇒ Might::FilterPredicates

Registers predicate on singular value or on array

Parameters:

  • predicate (String, Symbol)
  • on (:array, :value)

Returns:



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/might/filter_predicates.rb', line 59

def register(predicate, on:)
  case on
  when :value
    @predicates_on_value.add(predicate.to_s)
  when :array
    @predicates_on_array.add(predicate.to_s)
  else
    fail ArgumentError, 'on must be :array, or :value'
  end
  self
end

.valueSet<String>

Returns predicates for values

Returns:

  • (Set<String>)


83
84
85
# File 'lib/might/filter_predicates.rb', line 83

def value
  @predicates_on_value.dup
end