Module: Trailblazer::Finder::Adapters::ActiveRecord::Predicates

Defined in:
lib/trailblazer/finder/adapters/active_record/predicates.rb

Overview

ActiveRecord Predicates Adapter

Class Method Summary collapse

Class Method Details

.set_blank_handlerObject



28
29
30
31
32
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 28

def set_blank_handler
  ->(entity, attribute, _value) do
    entity.where(attribute.to_sym => [nil, ""])
  end
end

.set_cont_handlerObject



64
65
66
67
68
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 64

def set_cont_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} LIKE ?", "%#{value}%")
  end
end

.set_eq_handlerObject



12
13
14
15
16
17
18
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 12

def set_eq_handler
  ->(entity, attribute, value) do
    return if Utils::String.blank?(value.to_s)

    entity.where(attribute => value)
  end
end

.set_ew_handlerObject



88
89
90
91
92
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 88

def set_ew_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} LIKE ?", "%#{value}")
  end
end

.set_gt_handlerObject



40
41
42
43
44
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 40

def set_gt_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} > ?", value.to_f)
  end
end

.set_gte_handlerObject



46
47
48
49
50
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 46

def set_gte_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} >= ?", value.to_f)
  end
end

.set_lt_handlerObject



52
53
54
55
56
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 52

def set_lt_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} < ?", value.to_f)
  end
end

.set_lte_handlerObject



58
59
60
61
62
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 58

def set_lte_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} <= ?", value.to_f)
  end
end

.set_not_blank_handlerObject



34
35
36
37
38
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 34

def set_not_blank_handler
  ->(entity, attribute, _value) do
    entity.where.not(attribute.to_sym => [nil, ""])
  end
end

.set_not_cont_handlerObject



70
71
72
73
74
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 70

def set_not_cont_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} NOT LIKE ?", "%#{value}%")
  end
end

.set_not_eq_handlerObject



20
21
22
23
24
25
26
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 20

def set_not_eq_handler
  ->(entity, attribute, value) do
    return if Utils::String.blank?(value.to_s)

    entity.where.not(attribute => value)
  end
end

.set_not_ew_handlerObject



94
95
96
97
98
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 94

def set_not_ew_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} NOT LIKE ?", "%#{value}")
  end
end

.set_not_sw_handlerObject



82
83
84
85
86
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 82

def set_not_sw_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} NOT LIKE ?", "#{value}%")
  end
end

.set_sw_handlerObject



76
77
78
79
80
# File 'lib/trailblazer/finder/adapters/active_record/predicates.rb', line 76

def set_sw_handler
  ->(entity, attribute, value) do
    entity.where("#{attribute} LIKE ?", "#{value}%")
  end
end