kor-input-yaml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5dd331e9dda4ba71e23393dc1bf05c0b7ce7d43
4
+ data.tar.gz: 33bf11a35ab58d6bfc16e3679dcf2baf6f36a897
5
+ SHA512:
6
+ metadata.gz: b8b031fa5158e3d901d0773b0751fae89c9929aa864656fd6b7d5b3312b1fccc92f60eb0e394a1f0cfe551abb4fb3c0211dec61f91ed1d36f6eeb47ccf87e054
7
+ data.tar.gz: b0fc4540c9c3dd2c0d2cc95b5ec2aa37e3ee06b1e4051b29bf1aa4873bbc8d93195b14ccac72f1a11c97e8a6c965ef4edb7c236bfef28d27754a3a969139c0b6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.7
5
+ - 2.2.3
6
+ before_install: gem install bundler -v 1.10.6
7
+ notifications:
8
+ email: false
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kor-input-yaml.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ksss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ kor-input-yaml
2
+ ===
3
+
4
+ [![Build Status](https://travis-ci.org/ksss/kor-input-yaml.svg)](https://travis-ci.org/ksss/kor-input-yaml)
5
+
6
+ YAML input plugin for [kor](https://github.com/ksss/kor).
7
+
8
+ # Usage
9
+
10
+ ```
11
+ $ cat table.yaml
12
+ ---
13
+ foo: 100
14
+ bar: 200
15
+ ---
16
+ bar: 500
17
+ baz: 600
18
+
19
+ $ kor yaml csv < table.yml
20
+ foo,bar,baz
21
+ 100,200,
22
+ ,500,600
23
+
24
+ $ kor yaml markdown < table.yml
25
+ | foo | bar | baz |
26
+ | --- | --- | --- |
27
+ | 100 | 200 | |
28
+ | | 500 | 600 |
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'kor-input-yaml'
37
+ ```
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install kor-input-yaml
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ksss/kor-input-yaml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
55
+
56
+ ## Refs
57
+
58
+ - https://github.com/ksss/kor
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ sh "rgot -v #{Dir.glob("lib/**/*_test.rb").join(' ')}"
5
+ end
6
+
7
+ task :default => [:test]
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kor/input/yaml/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kor-input-yaml"
8
+ spec.version = Kor::Input::Yaml::VERSION
9
+ spec.authors = ["ksss"]
10
+ spec.email = ["co000ri@gmail.com"]
11
+
12
+ spec.summary = %q{YAML input plugin for kor.}
13
+ spec.description = %q{YAML input plugin for kor.}
14
+ spec.homepage = "https://github.com/ksss/kor-input-yaml"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "kor"
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rgot"
24
+ end
@@ -0,0 +1,78 @@
1
+ require 'yaml'
2
+
3
+ module Kor
4
+ module Input
5
+ class Yaml
6
+ def initialize(io)
7
+ @io = io
8
+ @keys = []
9
+ @yamls = []
10
+ @prekeys = nil
11
+ @count = 0
12
+ @fiber = Fiber.new do
13
+ @yamls.each do |yaml|
14
+ Fiber.yield @keys.map{ |k| yaml[k] }
15
+ end
16
+ # gets should be return nil when last
17
+ Fiber.yield nil
18
+ end
19
+ end
20
+
21
+ def parse(opt)
22
+ opt.on("--key=KEY", "preset keys (e.g. foo,bar,baz)") do |arg|
23
+ @prekeys = arg
24
+ end
25
+ end
26
+
27
+ def head
28
+ if @prekeys
29
+ line = @io.gets
30
+ if line.index(START) != 0
31
+ @io.seek(line.length, IO::SEEK_CUR)
32
+ end
33
+ @keys = @prekeys.split(",")
34
+ else
35
+ @yamls = YAML.load_stream(@io.read)
36
+ @keys = @yamls.map do |yaml|
37
+ yaml.keys
38
+ end
39
+ @keys.flatten!.uniq!
40
+ @keys
41
+ end
42
+ end
43
+
44
+ START = "---"
45
+ EOF = "\n"
46
+
47
+ def gets
48
+ if @prekeys
49
+ stock = ""
50
+ while line = @io.gets
51
+ stock << line
52
+ if line.index(START) == 0
53
+ break
54
+ end
55
+ end
56
+ if stock == ""
57
+ return nil
58
+ end
59
+ yaml = YAML.load(stock)
60
+ @count += 1
61
+ @keys.map{ |key| yaml[key] }
62
+ else
63
+ resume
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def resume
70
+ @fiber.resume
71
+ rescue FiberError
72
+ nil
73
+ end
74
+ end
75
+
76
+ require "kor/input/yaml/version"
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ module Kor
2
+ module Input
3
+ class Yaml
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,92 @@
1
+ require 'kor/input/yaml'
2
+
3
+ module KorInputYamlTest
4
+ def test_initialize(t)
5
+ _, err = go { Kor::Input::Yaml.new }
6
+ unless ArgumentError === err
7
+ t.error("expect raise an ArgumentError got #{err.class}:#{err}")
8
+ end
9
+
10
+ _, err = go { Kor::Input::Yaml.new(nil) }
11
+ if err != nil
12
+ t.error("expect not raise an error got #{err.class}:#{err}")
13
+ end
14
+ end
15
+
16
+ def ready
17
+ io = StringIO.new(<<-YAML)
18
+ ---
19
+ foo: 100
20
+ bar: 200
21
+ ---
22
+ bar: 500
23
+ baz: 600
24
+ YAML
25
+ Kor::Input::Yaml.new(io)
26
+ end
27
+
28
+ def test_head(t)
29
+ yaml = ready
30
+ head = yaml.head
31
+ expect = %w(foo bar baz)
32
+ if head != expect
33
+ t.error("expect #{expect} got #{head}")
34
+ end
35
+ end
36
+
37
+ def test_head_with_prekeys(t)
38
+ yaml = ready
39
+ opt = OptionParser.new
40
+ yaml.parse(opt)
41
+ opt.parse ["--key=bar,foo"]
42
+
43
+ head = yaml.head
44
+ expect = ["bar", "foo"]
45
+ if head != expect
46
+ t.error("expect #{expect} got #{head}")
47
+ end
48
+ end
49
+
50
+ def test_gets(t)
51
+ yaml = ready
52
+ yaml.head
53
+
54
+ expects = [
55
+ [100, 200, nil],
56
+ [nil, 500, 600],
57
+ nil, nil, nil, nil, nil
58
+ ].each do |expect|
59
+ actual = yaml.gets
60
+ if actual != expect
61
+ t.error("expect #{expect} got #{actual}")
62
+ end
63
+ end
64
+ end
65
+
66
+ def test_gets_with_prekeys(t)
67
+ yaml = ready
68
+ opt = OptionParser.new
69
+ yaml.parse(opt)
70
+ opt.parse ["--key=bar,foo"]
71
+ yaml.head
72
+
73
+ expects = [
74
+ [200, 100],
75
+ [500, nil],
76
+ nil, nil, nil, nil, nil
77
+ ].each do |expect|
78
+ actual = yaml.gets
79
+ if actual != expect
80
+ t.error("expect #{expect} got #{actual}")
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def go
88
+ [yield, nil]
89
+ rescue Exception => err
90
+ [nil, err]
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kor-input-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ksss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kor
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rgot
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: YAML input plugin for kor.
70
+ email:
71
+ - co000ri@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - kor-input-json.gemspec
84
+ - lib/kor/input/yaml.rb
85
+ - lib/kor/input/yaml/version.rb
86
+ - lib/kor/input/yaml_test.rb
87
+ homepage: https://github.com/ksss/kor-input-yaml
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: YAML input plugin for kor.
111
+ test_files: []