Class: ParamsReady::Query::GroupingOperator
- Inherits:
-
Object
- Object
- ParamsReady::Query::GroupingOperator
- Defined in:
- lib/params_ready/query/grouping.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #arel_method ⇒ Object
- #connect(a, b) ⇒ Object
- #test(record, predicates) ⇒ Object
- #test_method ⇒ Object
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
125 126 127 |
# File 'lib/params_ready/query/grouping.rb', line 125 def type @type end |
Class Method Details
.instance(type) ⇒ Object
127 128 129 130 |
# File 'lib/params_ready/query/grouping.rb', line 127 def self.instance(type) raise ParamsReadyError, "Unimplemented operator: #{type}" unless @instances.key? type @instances[type] end |
Instance Method Details
#==(other) ⇒ Object
155 156 157 158 |
# File 'lib/params_ready/query/grouping.rb', line 155 def ==(other) return false unless other.class <= GroupingOperator type == other.type end |
#arel_method ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/params_ready/query/grouping.rb', line 132 def arel_method case type when :and, :or then type else raise ParamsReadyError, "Unimplemented operator: #{type}" end end |
#connect(a, b) ⇒ Object
149 150 151 152 153 |
# File 'lib/params_ready/query/grouping.rb', line 149 def connect(a, b) return b if a.nil? return a if b.nil? a.send arel_method, b end |
#test(record, predicates) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/params_ready/query/grouping.rb', line 160 def test(record, predicates) definite = predicates.map do |predicate| predicate.test(record) end.compact return nil if definite.empty? definite.send(test_method) end |
#test_method ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/params_ready/query/grouping.rb', line 140 def test_method case type when :and then :all? when :or then :any? else raise ParamsReadyError, "Unimplemented operator: #{type}" end end |