module ActiveJson::CLI

Public Class Methods

reject(json, where: nil, pluck: nil) click to toggle source
# File lib/cli.rb, line 16
def reject(json, where: nil, pluck: nil)
  data = parse_json(json)
  return data unless where || pluck

  filter, pluck = build_query(where, pluck)
  Query.reject(data, where: filter, pluck: pluck)
end
select(json, where: nil, pluck: nil) click to toggle source
# File lib/cli.rb, line 8
def select(json, where: nil, pluck: nil)
  data = parse_json(json)
  return data unless where || pluck

  filter, pluck = build_query(where, pluck)
  Query.select(data, where: filter, pluck: pluck)
end

Private Class Methods

build_query(where, pluck) click to toggle source
# File lib/cli.rb, line 26
def build_query(where, pluck)
  [
    where&.split(',')&.map(&filter) || [],
    Pluck.new(pluck)
  ]
end
filter() click to toggle source
# File lib/cli.rb, line 37
def filter
  -> (attrs) { Filter.new(attrs.strip) }
end
parse_json(json) click to toggle source
# File lib/cli.rb, line 33
def parse_json(json)
  JSON.parse(json, symbolize_names: true)
end