json2yaml 0.0.1 → 0.0.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: 0437d4536334fcd96bde67c07c6b245e93a07125
4
- data.tar.gz: 2267658d5434009089afa431e5995d7e7de763c6
3
+ metadata.gz: e46194deb17804a4272e56ed0bd0b3b07886d9fe
4
+ data.tar.gz: 03533791357b43d1abcedeadbc6072bda1334921
5
5
  SHA512:
6
- metadata.gz: 1e37bd1bddf1424f2d30c379e415b5edb46b18031e3570d58ae492ab7afb631af43b1242c52f22555049009307a1ceed30c8333babd3ec3d1ddb18e728d16824
7
- data.tar.gz: 21dd07eb7fa606b4ad7687e63c1b974435721025764978023d3ae6dfca87120b3d6ed2d28c1ef75d4d5907113458aec3cd6a4045c44adbd63dd85cb6c8cf7491
6
+ metadata.gz: 2cb1e19c2b1eb75b24a9066deecae9d73695d6f979861680a0a962abe318ee43c4f5f8d2318427510415c5675460698d969f468d3fe9d4cc5d1c2690f07e5f16
7
+ data.tar.gz: dd940815742d9a40863d8c93307190cb132ddfd8f7bd44cd146db27203609064fc8a6e150a3438460d22ced74b9e3862a398dda1cf3fb797d0b6ff00920f3f35
@@ -6,3 +6,4 @@ rvm:
6
6
  - 1.8.7
7
7
  - 1.9.3
8
8
  - 2.0.0
9
+ - 2.1
@@ -3,4 +3,6 @@
3
3
 
4
4
  require 'json2yaml'
5
5
 
6
- print Json2yaml.to_yaml(STDIN.read)
6
+ Json2yaml.to_yaml(STDIN).each do |yaml|
7
+ print yaml
8
+ end
@@ -3,4 +3,6 @@
3
3
 
4
4
  require 'json2yaml'
5
5
 
6
- print Json2yaml.to_json(STDIN.read)
6
+ Json2yaml.to_json(STDIN).each do |json|
7
+ print json
8
+ end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "yajl-ruby"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  spec.add_development_dependency "rspec"
@@ -1,13 +1,21 @@
1
1
  require "json2yaml/version"
2
- require 'json'
2
+ require 'yajl/json_gem'
3
3
  require 'yaml'
4
4
 
5
5
  module Json2yaml
6
- def self.to_yaml(json)
7
- JSON.parse(json).to_yaml
6
+ def self.to_yaml(json_stream)
7
+ Enumerator.new do |yielder|
8
+ Yajl::Parser.new.parse(json_stream) do |d|
9
+ yielder.yield d.to_yaml
10
+ end
11
+ end
8
12
  end
9
13
 
10
- def self.to_json(yaml)
11
- YAML.load(yaml).to_json
14
+ def self.to_json(yaml_stream)
15
+ Enumerator.new do |yielder|
16
+ YAML.load_stream(yaml_stream) do |d|
17
+ yielder.yield d.to_json + "\n"
18
+ end
19
+ end
12
20
  end
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module Json2yaml
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,13 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Json2yaml do
4
- let(:json_str) { "{\"a\":\"b\"}" }
5
- let(:yaml_str) { "---\na: b\n" }
6
- context '.to_json' do
7
- it { expect(Json2yaml.to_yaml(json_str)).to eq(yaml_str) }
4
+ context "with single data" do
5
+ let(:json_str) { "{\"a\":\"b\"}\n" }
6
+ let(:yaml_str) { "---\na: b\n" }
7
+ let(:json_io) { StringIO.new(json_str, "r") }
8
+ let(:yaml_io) { StringIO.new(yaml_str, "r") }
9
+ context '.to_json' do
10
+ it { expect(Json2yaml.to_yaml(json_io).reduce(&:+)).to eq(yaml_str) }
11
+ end
12
+
13
+ context '.to_yaml' do
14
+ it { expect(Json2yaml.to_json(yaml_io).reduce(&:+)).to eq(json_str) }
15
+ end
8
16
  end
9
17
 
10
- context '.to_yaml' do
11
- it { expect(Json2yaml.to_json(yaml_str)).to eq(json_str) }
18
+ context "with multiple data" do
19
+ let(:json_str) { "{\"a\":\"b\"}\n{\"c\":\"d\"}\n{\"e\":\"f\"}\n" }
20
+ let(:yaml_str) { "---\na: b\n---\nc: d\n---\ne: f\n" }
21
+ let(:json_io) { StringIO.new(json_str, "r") }
22
+ let(:yaml_io) { StringIO.new(yaml_str, "r") }
23
+ context '.to_json' do
24
+ it { expect(Json2yaml.to_yaml(json_io).reduce(&:+)).to eq(yaml_str) }
25
+ end
26
+
27
+ context '.to_yaml' do
28
+ it { expect(Json2yaml.to_json(yaml_io).reduce(&:+)).to eq(json_str) }
29
+ end
12
30
  end
13
- end
31
+ end
metadata CHANGED
@@ -1,55 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json2yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yajl-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ~>
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
33
  version: '1.3'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ~>
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '>='
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  description: Convert between JSON and YAML in CLI
@@ -61,10 +75,10 @@ executables:
61
75
  extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
- - .coveralls.yml
65
- - .gitignore
66
- - .rspec
67
- - .travis.yml
78
+ - ".coveralls.yml"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
68
82
  - Gemfile
69
83
  - LICENSE.txt
70
84
  - README.md
@@ -86,20 +100,21 @@ require_paths:
86
100
  - lib
87
101
  required_ruby_version: !ruby/object:Gem::Requirement
88
102
  requirements:
89
- - - '>='
103
+ - - ">="
90
104
  - !ruby/object:Gem::Version
91
105
  version: '0'
92
106
  required_rubygems_version: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  requirements: []
98
112
  rubyforge_project:
99
- rubygems_version: 2.0.3
113
+ rubygems_version: 2.2.2
100
114
  signing_key:
101
115
  specification_version: 4
102
116
  summary: Convert between JSON and YAML in CLI
103
117
  test_files:
104
118
  - spec/json2yaml_spec.rb
105
119
  - spec/spec_helper.rb
120
+ has_rdoc: