jr-cli 0.3.1 → 0.4.0

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
  SHA1:
3
- metadata.gz: a2442d68bf0d7ae265d19dddfd2254a05a3d7da4
4
- data.tar.gz: f3c6eb02168b7d9f0610b311c80b664212a328de
3
+ metadata.gz: 3eb780e24677fc860ad761bc334ecb29eb45e09f
4
+ data.tar.gz: 695c705288ff8bd671a6bce707a5a96cc0ebacf0
5
5
  SHA512:
6
- metadata.gz: dadf8e4b869090d35222ef185e8b6408712ec677a488ea17bbd32cbcabe8982c32de577f51e3cf581a94dddd9d23b5009aba272d8760f213bb2f6499d0c598fa
7
- data.tar.gz: c1eed8b3f7804b65934b5a87405dfdf35de2c39ee0139c849b9b73b50dac667ad367adaa6c381de0004373770b65f3a3e3d155bea701a5805c37d465b6e9efff
6
+ metadata.gz: 61004562f569c2fcf351279c14d37bf4e286d66fff7d34277d019d5914173ba4d8a502906b1c785ce66cfb9e49fad623f048498e5d6f608c272d92a0935b7cff
7
+ data.tar.gz: 3584d348cef55a566aca3622b7639523436b521afc81e2ff3d0666cebc120a67752fa724ec5201de2e36e676b380d505a22f6ceae9638958bcccf4e5ea5de77a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.0 (2015-08-29)
2
+
3
+ * Add `--unbuffered` option
4
+
1
5
  ## 0.3.1 (2015-08-29)
2
6
 
3
7
  * Any `Enumerable` object except for `Hash` is enumerated
data/README.md CHANGED
@@ -40,6 +40,7 @@ You can also read JSON not from files but from STDIN.
40
40
  -C, --color-output output with colors even if writing to a pipe or a file
41
41
  -M, --monochrome-output output without colors
42
42
  -n, --null-input use null as input instead of any files
43
+ --unbuffered output each JSON without buffering
43
44
  ```
44
45
 
45
46
  ## jr filter tutorial
data/bin/jr CHANGED
@@ -6,6 +6,9 @@ require 'optparse'
6
6
  require 'yajl'
7
7
  require 'coderay'
8
8
 
9
+ DEFAULT_BUFFER_SIZE = 8192
10
+ UNBUFFERED_BUFFER_SIZE = 1
11
+
9
12
  opt = OptionParser.new
10
13
  opt.banner = "jr - Command-line JSON processor for Rubyists [Ver. #{Jr::Cli::VERSION}]\n\n" +
11
14
  "Usage: jr [options] <jr filter> [file...]"
@@ -25,6 +28,9 @@ opt.on('-C', '--color-output', 'output with colors even if writing to a pip
25
28
  opt.on('-M', '--monochrome-output', 'output without colors') { color_output = false }
26
29
  null_input = false
27
30
  opt.on('-n', '--null-input', 'use null as input instead of any files') { null_input = true }
31
+ unbuffered = false
32
+ buffer_size = DEFAULT_BUFFER_SIZE
33
+ opt.on('--unbuffered', 'output each JSON without buffering') { unbuffered = true; buffer_size = UNBUFFERED_BUFFER_SIZE }
28
34
  opt.parse! ARGV
29
35
 
30
36
  require 'jr/cli/core_ext'
@@ -53,7 +59,7 @@ else
53
59
  else
54
60
  input_enumerator = Enumerator.new do |yielder|
55
61
  inputs.each do |input|
56
- Yajl::Parser.new(symbolize_keys: true).parse(input) do |d|
62
+ Yajl::Parser.new(symbolize_keys: true).parse(input, buffer_size) do |d|
57
63
  yielder.yield d
58
64
  end
59
65
  end
@@ -79,6 +85,7 @@ end
79
85
  if result.is_a? Enumerable and !result.is_a? Hash
80
86
  result.each do |data|
81
87
  print_json.call data
88
+ STDOUT.flush if unbuffered
82
89
  end
83
90
  else
84
91
  print_json.call result
@@ -1,5 +1,5 @@
1
1
  module Jr
2
2
  module Cli
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jr-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Takeyama