embulk-filter-ruby_proc 0.6.0 → 0.7.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: 7745c13afc58b5b1e5257cf7f1025fc3292b8103
4
- data.tar.gz: fc8310448ff1cadba48dfb3cf59b64048749fc70
3
+ metadata.gz: 754bf37f61d14a24054997630406b8c9b02e7aff
4
+ data.tar.gz: c47c596b3745548ac8919e7be92727e6157bfd70
5
5
  SHA512:
6
- metadata.gz: 9ca41e0fff89bb94f82f1c5035682ee48203ccae6e6493bd8867f6da3eaef1580618a15e442776ad21280d9cf96c8e8e5c5381a0ac1fbe811fb843702b38ca28
7
- data.tar.gz: 8ba158fad7a3a5570bfdb3ad5186381cec5cf4a86eb927c022989e59a1e782fb5efa835ddc5d6470160b16edc28d1612402ad06ae2ce2be3019507b994422680
6
+ metadata.gz: acf1ee4540152e40b7e706466b67f1f4f48eb23d200c988a3d46fe21dce669c19897c8f000cfbcf55f600c7c908a9accd7b51b268ecc7c9ad92f1cf1c5a733df
7
+ data.tar.gz: d3757d66ef78d46463a533b436fb4ae58c2e8a7fe09c9baad6c238eaca5204a5d6b76de095c7733ffa6e9f289056d7879e6e2e6fe534a82c7c83cbe55bde5fa6
@@ -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.6.0"
4
+ spec.version = "0.7.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"
@@ -113,9 +113,39 @@ module Embulk
113
113
  @row_proc_store
114
114
  end
115
115
 
116
+ def self.parse_col_procs(columns, evaluator_binding)
117
+ Hash[columns.map {|col|
118
+ if col["proc"]
119
+ [col["name"], eval(col["proc"], evaluator_binding)]
120
+ else
121
+ [col["name"], eval(File.read(col["proc_file"]), evaluator_binding, File.expand_path(col["proc_file"]))]
122
+ end
123
+ }]
124
+ end
125
+
126
+ def self.parse_row_procs(rows, evaluator_binding)
127
+ rows.map {|rowdef|
128
+ if rowdef["proc"]
129
+ eval(rowdef["proc"], evaluator_binding)
130
+ else
131
+ eval(File.read(rowdef["proc_file"]), evaluator_binding, File.expand_path(rowdef["proc_file"]))
132
+ end
133
+ }.compact
134
+ end
135
+
116
136
  def init
117
- @procs = self.class.proc_store[task["transaction_id"]]
118
- @row_procs = self.class.row_proc_store[task["transaction_id"]]
137
+ task["requires"].each do |lib|
138
+ require lib
139
+ end
140
+
141
+ if self.class.proc_store.nil? || self.class.row_proc_store.nil?
142
+ evaluator_binding = Evaluator.new(task["variables"]).get_binding
143
+ @procs = self.class.parse_col_procs(task["columns"], evaluator_binding)
144
+ @row_procs = self.class.parse_row_procs(task["rows"], evaluator_binding)
145
+ else
146
+ @procs = self.class.proc_store[task["transaction_id"]]
147
+ @row_procs = self.class.row_proc_store[task["transaction_id"]]
148
+ end
119
149
  @skip_nils = Hash[task["columns"].map {|col|
120
150
  [col["name"], col["skip_nil"].nil? ? true : !!col["skip_nil"]]
121
151
  }]
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.6.0
4
+ version: 0.7.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-04-15 00:00:00.000000000 Z
11
+ date: 2016-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: embulk