module ActiveJson::Query
Public Instance Methods
reject(data, where:, pluck: nil)
click to toggle source
# File lib/active_json/query.rb, line 12 def reject(data, where:, pluck: nil) result = array(data).reject(&apply_filters(where)) pluck ? result.map(&pluck_attributes(pluck)).compact : result end
select(data, where:, pluck: nil)
click to toggle source
# File lib/active_json/query.rb, line 7 def select(data, where:, pluck: nil) result = array(data).select(&apply_filters(where)) pluck ? result.map(&pluck_attributes(pluck)).compact : result end
Private Instance Methods
apply_filters(filters)
click to toggle source
# File lib/active_json/query.rb, line 19 def apply_filters(filters) -> (record) do filters.all? { |filter| filter.call(record) } end end
array(elem)
click to toggle source
# File lib/active_json/query.rb, line 29 def array(elem) elem.is_a?(Array) ? elem : [elem] end
pluck_attributes(pluck)
click to toggle source
# File lib/active_json/query.rb, line 25 def pluck_attributes(pluck) -> (record) { pluck.call(record) } end