embulk-filter-script_ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f54ddf1485b39ed55c2f4a0d90e436ade35865d2
4
+ data.tar.gz: 4e1c9486b03eb6a08db25ab907f66074a10fef3e
5
+ SHA512:
6
+ metadata.gz: 37f5be1016a5ffe42a52e638ddcfad8e9aedc40e5b1b1f7ee662b85d0703ff6c24dc0b92f34b7be4cb1eeb1a0907c264b8ea2ec6d11d4490dd5828d92f5ededb
7
+ data.tar.gz: 9e81a17d122fc3ecc0e97fd8b0213c67b8bc3a3bc97400a93bf3cc89d72397c321b0eb97232aec423d0e9d6b774bd00e15470c80a2a3d9ab4126ca37b124da1b
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-9.0.4.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Script Ruby filter plugin for Embulk
2
+
3
+ TODO: Write short description here and embulk-filter-script_ruby.gemspec file.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: filter
8
+
9
+ ## Configuration
10
+
11
+ - **script**: script file (string, required)
12
+ - **class**: class name (string, required)
13
+ - **columns**: output columns (array, default: `null`)
14
+
15
+ ## Example
16
+
17
+ ```yaml
18
+ filters:
19
+ - type: script_ruby
20
+ script: filter_hoge
21
+ class: FilterHoge
22
+ columns:
23
+ - {name: id, type: string}
24
+ ...
25
+ ```
26
+
27
+ script ファイルは./script/ 以下に置く
28
+
29
+ filter_hoge.rb
30
+ ```ruby
31
+ class FilterHoge
32
+ def initialize()
33
+ ...
34
+ end
35
+
36
+ def filter(record)
37
+ ...
38
+ record
39
+ end
40
+ end
41
+ ```
42
+
43
+ ## Build
44
+
45
+ ```
46
+ $ rake
47
+ ```
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-filter-script_ruby"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["shinjiikeda"]
6
+ spec.summary = "Script Ruby filter plugin for Embulk"
7
+ spec.description = "Script Ruby"
8
+ spec.email = ["gm.ikeda@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/shinjiikeda/embulk-filter-script_ruby"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ #spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.9']
18
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
19
+ spec.add_development_dependency 'rake', ['>= 10.0']
20
+ end
@@ -0,0 +1,66 @@
1
+ module Embulk
2
+ module Filter
3
+
4
+ class ScriptRuby < FilterPlugin
5
+ Plugin.register_filter("script_ruby", self)
6
+
7
+ def self.transaction(config, in_schema, &control)
8
+ # configuration code:
9
+ task = {
10
+ 'script' => config.param('script', :string),
11
+ 'class' => config.param('class', :string),
12
+ 'columns' => config.param('columns', :array, default: [])
13
+ }
14
+
15
+ c = 0
16
+ out_columns = task['columns'].map do | e |
17
+ col = Column.new(c, e['name'], e['type'].to_sym)
18
+ c+=1
19
+ col
20
+ end
21
+
22
+ yield(task, out_columns)
23
+ end
24
+
25
+ def init
26
+ # initialization code:
27
+ @script = task['script']
28
+
29
+ @out_map = {}
30
+ out_schema.each do | e |
31
+ @out_map[e['name']] = true
32
+ end
33
+
34
+ $:.unshift "./script/"
35
+ require @script
36
+ @filter_class = Object.const_get(task['class']).new()
37
+ end
38
+
39
+ def close
40
+ end
41
+
42
+ def add(page)
43
+ # filtering code:
44
+ page.each do |record|
45
+ begin
46
+ h = Hash[in_schema.names.zip(record)]
47
+ result = @filter_class.filter(h)
48
+ out_record = []
49
+ out_schema.sort_by{|e| e['index']}.each do | e |
50
+ out_record << result[e['name']] if result.has_key?(e['name'])
51
+ end
52
+ page_builder.add(out_record) if out_record.size > 0
53
+ rescue => e
54
+ raise e.to_s + " backtrace: " + e.backtrace.to_s
55
+ end
56
+ end
57
+ end
58
+
59
+ def finish
60
+ page_builder.finish
61
+ end
62
+ end
63
+
64
+
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-script_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shinjiikeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.9
19
+ name: embulk
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.6
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.6
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Script Ruby
56
+ email:
57
+ - gm.ikeda@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - embulk-filter-script_ruby.gemspec
69
+ - lib/embulk/filter/script_ruby.rb
70
+ homepage: https://github.com/shinjiikeda/embulk-filter-script_ruby
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Script Ruby filter plugin for Embulk
94
+ test_files: []