8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/model/querying/querying.rb', line 8
def query(params={}, &filter_condition)
path_values, selected_keys = [], []
own_path_keys.each do |key|
if params[key]
path_values << path_value_param(params[key])
selected_keys << key
else
break
end
end
full_path = ([ collection_name ] + path_values) * LEVEL_SEPARATOR
response = connection.get(full_path).body
return [] if response.nil?
result = down_levels(response, (own_path_keys - selected_keys).count)
filter = params.clone
selected_keys.each do |sk|
filter.delete(sk)
end
result.map{|data| new(data) }.select do |model_object|
not_filtered_by_attributes = model_object.has_data?(filter)
not_filtered_by_block = block_given? ? filter_condition.(model_object) : true
not_filtered_by_attributes && not_filtered_by_block
end
end
|