active_json_cli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1843965e895a4c12245c8d83919ced4ae7a4531878850efc648d2ed131bbe9f
4
- data.tar.gz: '0068f99a699e3081963061aeb0ed2af9dc9cca1a099984ba5b0f9a4f785b5d4e'
3
+ metadata.gz: 00b1050d2e8e3fc75bfff973e5625faebb5eb5546c9f357cc2c3ebb97be2c133
4
+ data.tar.gz: 8940e6f6ae2877cfd69c15668ade74efa081c02f0a77f4a4d1bcf48f1fb6dcc9
5
5
  SHA512:
6
- metadata.gz: 634388d572a8e98fce84283e930554a9874abd9a1d6b1b7d6236e120ee8af9640f9eb5adf44e3a5b9c5c2368931734b41e5139a303eeb6e15e6bb0111203c0ef
7
- data.tar.gz: a238c6996b978cb3abe2238057ad262f94c86d4fa46eaa515f3d74f1471064c7a4ebe3956ac92fd37fa43ea21c3a49962378fa2a00591ddc0103167642a75120
6
+ metadata.gz: 730bc7426b800773b8bd56f2b16983b5d2db73d8dcf8eab80928631d518933b8233bad88b6eaffc811dcd39998cbdfa4ae8f8a058309112a0c8a4867189c043d
7
+ data.tar.gz: 0e0820ea84515ba7652fe23e341d24cad62401cfda25f904c6ac176b818cd333248cfab22b5f28a3622b6742bab762bd89e96bc92fbc3d6186aa49359a38efef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_json_cli (0.1.0)
4
+ active_json_cli (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -29,21 +29,21 @@ Filter JSON content with the `where` keyword followed by an attribute comparison
29
29
 
30
30
  For example running the following command...
31
31
 
32
- $ bin/active_json example.json where: 'drink_name == "latte"'
32
+ $ active_json example.json where: 'drink_name == "latte"'
33
33
 
34
34
  ...will return all entries whose `drink_name` keyword is "latte"
35
35
 
36
36
  If the JSON contains nested content you are able to query it as well:
37
37
 
38
- $ bin/active_json example.json where: 'prices.small >= 3.5'
38
+ $ active_json example.json where: 'prices.small >= 3.5'
39
39
 
40
40
  You are able chain any number of filters:
41
41
 
42
- $ bin/active_json example.json where: 'drink_name == "latte", prices.small <= 3.5'
42
+ $ active_json example.json where: 'drink_name == "latte", prices.small <= 3.5'
43
43
 
44
44
  You can also compare attributes with one another:
45
45
 
46
- $ bin/active_json example.json where: 'prices.small >= prices.large'
46
+ $ active_json example.json where: 'prices.small >= prices.large'
47
47
 
48
48
  Running the command without a `where` filter will return all JSON entries.
49
49
 
@@ -51,7 +51,7 @@ Running the command without a `where` filter will return all JSON entries.
51
51
 
52
52
  If you would rather return a particular attribute rather than the whole entry you can use the `pluck` keyword to only return a specified attribute. Running...
53
53
 
54
- $ bin/active_json example.json where: 'drink_name == "latte"' pluck: prices.small
54
+ $ active_json example.json where: 'drink_name == "latte"' pluck: prices.small
55
55
 
56
56
  ...will return the `prices.small` attribute of all the entries whose `drink_name` keyword is "latte"
57
57
 
Binary file
data/bin/active_json CHANGED
@@ -7,6 +7,9 @@ require 'json'
7
7
 
8
8
  json_path, *args = ARGV
9
9
 
10
+ abort('Please provide a filepath') if json_path.nil? || json_path.empty?
11
+ abort('File provided is not JSON') unless json_path.end_with?('.json')
12
+
10
13
  json = IO.read(json_path)
11
14
 
12
15
  filters, attribute =
@@ -1,3 +1,3 @@
1
1
  module ActiveJson
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/cli.rb CHANGED
@@ -5,14 +5,18 @@ module ActiveJson
5
5
  module CLI
6
6
  class << self
7
7
 
8
- def select(json, where:, pluck: nil)
8
+ def select(json, where: nil, pluck: nil)
9
9
  data = parse_json(json)
10
+ return data unless where || pluck
11
+
10
12
  filter, pluck = build_query(where, pluck)
11
13
  Query.select(data, where: filter, pluck: pluck)
12
14
  end
13
15
 
14
- def reject(json, where:, pluck: nil)
16
+ def reject(json, where: nil, pluck: nil)
15
17
  data = parse_json(json)
18
+ return data unless where || pluck
19
+
16
20
  filter, pluck = build_query(where, pluck)
17
21
  Query.reject(data, where: filter, pluck: pluck)
18
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_json_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah
@@ -98,6 +98,7 @@ files:
98
98
  - README.md
99
99
  - Rakefile
100
100
  - active_json_cli-0.1.0.gem
101
+ - active_json_cli-0.1.1.gem
101
102
  - active_json_cli.gemspec
102
103
  - bin/active_json
103
104
  - bin/console