embulk-filter-script 0.0.1
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 +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/embulk-filter-script.gemspec +17 -0
- data/lib/embulk/filter/script.rb +62 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c152ab14bc52fcbe91dbb6b1881879f6aa63fbf1
|
4
|
+
data.tar.gz: 5b0fba2c0796acaad24c1a63858c3e33c0bd5a4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d08e0e14647a0e07e4abc4703798444ae4c743849db8e51eb4b91c3d8ce5ce31e792ba502a62253a73980960f0f6d2e19e121db0d6c57002d9d8e5fb82abc24b
|
7
|
+
data.tar.gz: 6627da3672c0e87c7d7dd0915c932c9265d17f3d89f66625c7383a4665764e256eeab260039727345a8a2dd4eade3a1046c407e8b3d9908fa258fbbde0ea07a3
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 SNakano
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "embulk-filter-script"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.licenses = ["MIT"]
|
5
|
+
s.summary = "Embulk filter plugin to external ruby script"
|
6
|
+
s.description = s.summary
|
7
|
+
s.authors = ["SNakano"]
|
8
|
+
s.email = ["pp.nakano@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/SNakano/embulk-filter-script"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
|
14
|
+
s.add_development_dependency 'embulk', '~> 0.7.9'
|
15
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
16
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Filter
|
3
|
+
|
4
|
+
class Script < FilterPlugin
|
5
|
+
Plugin.register_filter('script', self)
|
6
|
+
|
7
|
+
def self.transaction(config, in_schema, &control)
|
8
|
+
task = {
|
9
|
+
'path' => config.param('path', :string),
|
10
|
+
'drop_columns' => config.param('drop_columns', :array, default: [])
|
11
|
+
}
|
12
|
+
out_schema = out_schema(task['drop_columns'], in_schema)
|
13
|
+
yield(task, out_schema)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.out_schema(drop_columns, in_schema)
|
17
|
+
idx = 0
|
18
|
+
schema = []
|
19
|
+
in_schema.each do |sch|
|
20
|
+
unless drop_columns.find {|n| n == sch.name}
|
21
|
+
schema << Column.new(idx, sch.name, sch.type, sch.format)
|
22
|
+
idx += 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
schema
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(task, in_schema, out_schema, page_builder)
|
29
|
+
super
|
30
|
+
load_script_file(task['path'])
|
31
|
+
end
|
32
|
+
|
33
|
+
def add(page)
|
34
|
+
task
|
35
|
+
page.each do |record|
|
36
|
+
result = {}
|
37
|
+
filter(hash_record(record)).each do |key, value|
|
38
|
+
unless task['drop_columns'].find {|n| n == key }
|
39
|
+
result[key] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@page_builder.add(result.values)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def finish
|
47
|
+
@page_builder.finish
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def load_script_file(path)
|
53
|
+
raise ConfigError, "Ruby script file does not exist: #{path}" unless File.exist?(path)
|
54
|
+
eval "self.instance_eval do;" + IO.read(path) + ";end"
|
55
|
+
end
|
56
|
+
|
57
|
+
def hash_record(record)
|
58
|
+
Hash[in_schema.names.zip(record)]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-filter-script
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SNakano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: embulk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.9
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.9
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
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
|
+
description: Embulk filter plugin to external ruby script
|
56
|
+
email:
|
57
|
+
- pp.nakano@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- embulk-filter-script.gemspec
|
67
|
+
- lib/embulk/filter/script.rb
|
68
|
+
homepage: https://github.com/SNakano/embulk-filter-script
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.5.1
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Embulk filter plugin to external ruby script
|
92
|
+
test_files: []
|