outstream-json 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
  SHA1:
3
- metadata.gz: f930b16d521d2755bfe9d6d7d2991f9462dc9966
4
- data.tar.gz: 860c74f446317f9f211f1e5108446dec9f0dfe53
3
+ metadata.gz: bb23d15ac017bb74a60f4d8b5d939ca4ea6a5220
4
+ data.tar.gz: 850a1a01ec27e3f663a106ffc420ed858bdeda03
5
5
  SHA512:
6
- metadata.gz: da4a08d92ab64858294421f6edef1a3250e5d0d4b4470c27c256506f36781d29861e036b3ff018d5a97d605739b897247e0030d6eba5585d922869b1e40c7bd6
7
- data.tar.gz: 6d344e5dbac4cedd94abc099f6c3259db530bcd410eb5838954034e6e942901abf5a12039a985d4f287a20079c316a786db6bcc4ce7bc6e5930617f15ca0cfef
6
+ metadata.gz: 2ef5dc77093aa2024ac51a95da3729e5d3acc74bdb88585e633e5aeb9cf1d64fc9dc7fc64308e89adb4b0fdfe0f79729eeda92520d0baa2b178f6f508f69ee59
7
+ data.tar.gz: e482b9774860e128bc00aa10c397a5303013661378682cd837720ec7f52df1e82b4f2e342842a6b203323366ed012ded2b0d011da44de1f5570f45f4a229f600
data/README.md CHANGED
@@ -25,7 +25,7 @@ The Json.create method defines a JSON object
25
25
  out = Outstream::Json.create do
26
26
  ...
27
27
  end
28
- # use out.to_s or out.each to product result
28
+ # use out.to_s or out.each to produce result
29
29
 
30
30
  Use with basic ruby types
31
31
 
@@ -35,17 +35,22 @@ Use with basic ruby types
35
35
  end
36
36
  # {"string":"hello","number":42,"array":[1,2,3]}
37
37
 
38
+ Use with hashes or blocks to create nested objects
39
+
38
40
  Outstream::Json.create do
39
- add "nested_object" {
40
- add "foo" => "bar"
41
+ add "block_object" do
42
+ add "foo" => "bar"
43
+ end
44
+ add "hash_object" => {
45
+ "wow" => "cool"
41
46
  }
42
47
  end
43
- # {"nested_object":{"foo":"bar"}}
48
+ # {"block_object":{"foo":"bar"},"hash_object":{"wow":"cool"}}
44
49
 
45
50
  Use with transformed SQL result set
46
51
 
47
52
  client = Mysql2::Client.new
48
- results = client.query("SELECT * FROM huge\_table", stream: true)
53
+ results = client.query("SELECT * FROM hugetable", stream: true)
49
54
  Outstream::Json.create do
50
55
  add results: results.lazy.map {|row| transform_row(row)}
51
56
  end
@@ -23,13 +23,19 @@ module Outstream
23
23
  # and string values as quoted strings. If called without a block, returns an enumerator.
24
24
  #
25
25
  # Example:
26
- # json.each {|token| puts token}
26
+ # json.each {|token| puts token} => nil
27
+ # json.each => an_enumerator
27
28
  def each(&out_block)
28
29
  e = Enumerator.new {|yielder|
29
30
  Collector.new(yielder).collect &@body_block
30
31
  }
31
32
 
32
- out_block ? e.each(&out_block) : e
33
+ if out_block
34
+ e.each(&out_block)
35
+ nil
36
+ else
37
+ e
38
+ end
33
39
  end
34
40
 
35
41
  # Produce a compact string of the JSON. The entire string is produced at once; this is not
data/test/test_json.rb CHANGED
@@ -31,7 +31,7 @@ class TestJson < Test::Unit::TestCase
31
31
  end
32
32
  def testHash
33
33
  out = Outstream::Json.create {
34
- add "foo" => {a: 1, b: 2}
34
+ add "foo" => { a: 1, b: 2 }
35
35
  }
36
36
  assert_equal '{"foo":{"a":1,"b":2}}', out.to_s
37
37
  end
@@ -76,6 +76,15 @@ class TestJson < Test::Unit::TestCase
76
76
  assert_equal '{"foo":"bar","wow":"cool"}', out.to_s
77
77
  end
78
78
 
79
+ def testEachBlock
80
+ out = Outstream::Json.create {
81
+ add "foo" => "bar"
82
+ }
83
+ tokens = []
84
+ assert_equal nil, out.each {|str| tokens << str}
85
+ assert_equal %w({ "foo" : "bar" }), tokens
86
+ end
87
+
79
88
  def testEnumerator
80
89
  x = "fun"
81
90
  out = Outstream::Json.create {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outstream-json
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
  - Ryan Calhoun