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

Class Method Summary collapse

Class Method Details

.allSet<String>

Returns all predicates

Returns:

  • (Set<String>)


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

def all
  @predicates_on_value + @predicates_on_array
end

.arraySet<String>

Returns predicates for array

Returns:

  • (Set<String>)


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

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:



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

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>)


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

def value
  @predicates_on_value.dup
end