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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/active_json_cli-0.1.1.gem +0 -0
- data/bin/active_json +3 -0
- data/lib/active_json/version.rb +1 -1
- data/lib/cli.rb +6 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b1050d2e8e3fc75bfff973e5625faebb5eb5546c9f357cc2c3ebb97be2c133
|
4
|
+
data.tar.gz: 8940e6f6ae2877cfd69c15668ade74efa081c02f0a77f4a4d1bcf48f1fb6dcc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 730bc7426b800773b8bd56f2b16983b5d2db73d8dcf8eab80928631d518933b8233bad88b6eaffc811dcd39998cbdfa4ae8f8a058309112a0c8a4867189c043d
|
7
|
+
data.tar.gz: 0e0820ea84515ba7652fe23e341d24cad62401cfda25f904c6ac176b818cd333248cfab22b5f28a3622b6742bab762bd89e96bc92fbc3d6186aa49359a38efef
|
data/Gemfile.lock
CHANGED
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
|
-
$
|
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
|
-
$
|
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
|
-
$
|
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
|
-
$
|
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
|
-
$
|
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
data/lib/active_json/version.rb
CHANGED
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
|
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
|
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.
|
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
|