100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/query_packwerk/query_interface.rb', line 100
def where(**query_params, &_query_fn)
query_keys = query_params.keys
all_values = all
accepted_keys = all_values.first.deconstruct_keys(nil).keys
invalid_keys = query_keys - accepted_keys
raise ArgumentError, "The following keys are invalid for querying: #{invalid_keys.join(', ')}" if invalid_keys.any?
all_values.select do |value|
next yield(value) if block_given?
object_params = value.deconstruct_keys(query_keys)
query_params.all? do |param, query_matcher|
object_value = object_params[param]
case [query_matcher, object_value]
in [Array, Array]
intersects?(query_matcher, object_value)
in [Array, _]
any_compare?(query_matcher, object_value)
in [_, Array]
includes?(query_matcher, object_value)
else
case_equal?(query_matcher, object_value)
end
end
end
end
|