embulk-filter-ruby_proc 0.3.0 → 0.4.0

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: b9a7bffd90b4924602a9fc0378f77b781ab05376
4
- data.tar.gz: 48134bc5631972efc8286573543dbfb9d312abab
3
+ metadata.gz: f44bc455c56121e98574eec9b504efbc5eb81649
4
+ data.tar.gz: 2f2176f8005b98e3e98e212900b84a0543431e4f
5
5
  SHA512:
6
- metadata.gz: c708ef11682d2b028b4f8adb70b41cb56b25ed63ef6575ffed9e7e4ab09d221d33e43eccde221923582924a342e57a4fea1e9cb4260838f98b9fc4e0dbf22647
7
- data.tar.gz: 583880f5a19829ed75ac4c11ef34c55ae12c5a1291f2a414890d9ce4f7a4e9de7c78a627e96d12a0807b5f5bd2f01a93112e37819c3d65f0b9c1f3c484a78ded
6
+ metadata.gz: 9b0d6f4d04a55d8d71d437f41903b652aa1dd6f240072bb4da36dc15d45d061ce7140e9464a69dd0cc24018cc77c3c832a01912164abaab05ebd756f2d6aef1f
7
+ data.tar.gz: 340bb8f0cd0be037dde1262a59990bcfbc9ed1bccf865c6fcefb1567fbeb6353b879f91e5bf4271453aaa60af3c96fddfe043365ececbe3491504848c93c9d62
data/README.md CHANGED
@@ -32,6 +32,8 @@ filters:
32
32
  - type: ruby_proc
33
33
  requires:
34
34
  - cgi
35
+ variables:
36
+ multiply: 3
35
37
  rows:
36
38
  - proc: |
37
39
  ->(record) do
@@ -49,7 +51,7 @@ filters:
49
51
  - name: id
50
52
  proc: |
51
53
  ->(id) do
52
- id * 2
54
+ id * variables["multiply"]
53
55
  end
54
56
  type: string
55
57
  - name: comment
@@ -78,14 +80,14 @@ And user must take care of object identity. Otherwise, error may be occurred whe
78
80
  +-----------+--------------+-------------------------+-------------------------+------------------------------------------+------------------------------------------------------------------------------------------+
79
81
  | id:string | account:long | time:timestamp | purchase:timestamp | comment:json | data:json |
80
82
  +-----------+--------------+-------------------------+-------------------------+------------------------------------------+------------------------------------------------------------------------------------------+
81
- | 2 | 32,864 | 2015-01-27 19:23:49 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK"] | {"events":[{"id":1,"name":"Name1","idx":0},{"id":2,"name":"Name2","idx":1}],"foo":"bar"} |
82
- | 22 | 32,864 | 2015-01-27 19:23:49 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK"] | {"events":[{"id":1,"name":"Name1","idx":0},{"id":2,"name":"Name2","idx":1}],"foo":"bar"} |
83
- | 4 | 14,824 | 2015-01-27 19:01:23 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK","JRUBY"] | |
84
- | 24 | 14,824 | 2015-01-27 19:01:23 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK","JRUBY"] | |
85
- | 6 | 27,559 | 2015-01-28 02:20:02 UTC | 2015-01-28 00:00:00 UTC | ["EMBULK","%22CSV%22","PARSER","PLUGIN"] | |
86
- | 26 | 27,559 | 2015-01-28 02:20:02 UTC | 2015-01-28 00:00:00 UTC | ["EMBULK","%22CSV%22","PARSER","PLUGIN"] | |
87
- | 8 | 11,270 | 2015-01-29 11:54:36 UTC | 2015-01-29 00:00:00 UTC | ["11270"] | |
88
- | 28 | 11,270 | 2015-01-29 11:54:36 UTC | 2015-01-29 00:00:00 UTC | ["11270"] | |
83
+ | 3 | 32,864 | 2015-01-27 19:23:49 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK"] | {"events":[{"id":1,"name":"Name1","idx":0},{"id":2,"name":"Name2","idx":1}],"foo":"bar"} |
84
+ | 33 | 32,864 | 2015-01-27 19:23:49 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK"] | {"events":[{"id":1,"name":"Name1","idx":0},{"id":2,"name":"Name2","idx":1}],"foo":"bar"} |
85
+ | 6 | 14,824 | 2015-01-27 19:01:23 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK","JRUBY"] | |
86
+ | 36 | 14,824 | 2015-01-27 19:01:23 UTC | 2015-01-27 00:00:00 UTC | ["EMBULK","JRUBY"] | |
87
+ | 9 | 27,559 | 2015-01-28 02:20:02 UTC | 2015-01-28 00:00:00 UTC | ["EMBULK","%22CSV%22","PARSER","PLUGIN"] | |
88
+ | 39 | 27,559 | 2015-01-28 02:20:02 UTC | 2015-01-28 00:00:00 UTC | ["EMBULK","%22CSV%22","PARSER","PLUGIN"] | |
89
+ | 12 | 11,270 | 2015-01-29 11:54:36 UTC | 2015-01-29 00:00:00 UTC | ["11270"] | |
90
+ | 42 | 11,270 | 2015-01-29 11:54:36 UTC | 2015-01-29 00:00:00 UTC | ["11270"] | |
89
91
  +-----------+--------------+-------------------------+-------------------------+------------------------------------------+------------------------------------------------------------------------------------------+
90
92
  ```
91
93
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-filter-ruby_proc"
4
- spec.version = "0.3.0"
4
+ spec.version = "0.4.0"
5
5
  spec.authors = ["joker1007"]
6
6
  spec.summary = "Ruby Proc filter plugin for Embulk"
7
7
  spec.description = "Filter each record by ruby proc"
data/example/config.yml CHANGED
@@ -25,6 +25,8 @@ filters:
25
25
  - type: ruby_proc
26
26
  requires:
27
27
  - cgi
28
+ variables:
29
+ multiply: 3
28
30
  rows:
29
31
  - proc: |
30
32
  ->(record) do
@@ -42,7 +44,7 @@ filters:
42
44
  - name: id
43
45
  proc: |
44
46
  ->(id) do
45
- id * 2
47
+ id * variables["multiply"]
46
48
  end
47
49
  type: string
48
50
  - name: comment
@@ -1,6 +1,17 @@
1
1
  module Embulk
2
2
  module Filter
3
3
 
4
+ class Evaluator
5
+ attr_reader :variables
6
+ def initialize(variables)
7
+ @variables = variables
8
+ end
9
+
10
+ def get_binding
11
+ binding
12
+ end
13
+ end
14
+
4
15
  class RubyProc < FilterPlugin
5
16
  Plugin.register_filter("ruby_proc", self)
6
17
 
@@ -9,6 +20,7 @@ module Embulk
9
20
  "columns" => config.param("columns", :array, default: []),
10
21
  "rows" => config.param("rows", :array, default: []),
11
22
  "requires" => config.param("requires", :array, default: []),
23
+ "variables" => config.param("variables", :hash, default: {}),
12
24
  }
13
25
 
14
26
  out_columns = in_schema.map do |col|
@@ -29,18 +41,20 @@ module Embulk
29
41
  require lib
30
42
  end
31
43
 
44
+ evaluator_binding = Evaluator.new(task["variables"]).get_binding
45
+
32
46
  @procs = Hash[task["columns"].map {|col|
33
47
  if col["proc"]
34
- [col["name"], eval(col["proc"])]
48
+ [col["name"], eval(col["proc"], evaluator_binding)]
35
49
  else
36
- [col["name"], eval(File.read(col["proc_file"]), binding, File.expand_path(col["proc_file"]))]
50
+ [col["name"], eval(File.read(col["proc_file"]), evaluator_binding, File.expand_path(col["proc_file"]))]
37
51
  end
38
52
  }]
39
53
  @row_procs = task["rows"].map {|rowdef|
40
54
  if rowdef["proc"]
41
- eval(rowdef["proc"])
55
+ eval(rowdef["proc"], evaluator_binding)
42
56
  else
43
- eval(File.read(rowdef["proc_file"]), binding, File.expand_path(rowdef["proc_file"]))
57
+ eval(File.read(rowdef["proc_file"]), evaluator_binding, File.expand_path(rowdef["proc_file"]))
44
58
  end
45
59
  }.compact
46
60
  raise "Need columns or rows parameter" if @row_procs.empty? && @procs.empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-ruby_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: embulk