Class: Embulk::Filter::Script
- Inherits:
-
FilterPlugin
- Object
- FilterPlugin
- Embulk::Filter::Script
- Defined in:
- lib/embulk/filter/script.rb
Class Method Summary collapse
- .out_schema(drop_columns, in_schema) ⇒ Object
- .transaction(config, in_schema) {|task, out_schema| ... } ⇒ Object
Instance Method Summary collapse
- #add(page) ⇒ Object
- #finish ⇒ Object
-
#initialize(task, in_schema, out_schema, page_builder) ⇒ Script
constructor
A new instance of Script.
Constructor Details
#initialize(task, in_schema, out_schema, page_builder) ⇒ Script
Returns a new instance of Script.
28 29 30 31 |
# File 'lib/embulk/filter/script.rb', line 28 def initialize(task, in_schema, out_schema, page_builder) super load_script_file(task['path']) end |
Class Method Details
.out_schema(drop_columns, in_schema) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/embulk/filter/script.rb', line 16 def self.out_schema(drop_columns, in_schema) idx = 0 schema = [] in_schema.each do |sch| unless drop_columns.find {|n| n == sch.name} schema << Column.new(idx, sch.name, sch.type, sch.format) idx += 1 end end schema end |
.transaction(config, in_schema) {|task, out_schema| ... } ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/embulk/filter/script.rb', line 7 def self.transaction(config, in_schema, &control) task = { 'path' => config.param('path', :string), 'drop_columns' => config.param('drop_columns', :array, default: []) } out_schema = out_schema(task['drop_columns'], in_schema) yield(task, out_schema) end |
Instance Method Details
#add(page) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/embulk/filter/script.rb', line 33 def add(page) task page.each do |record| result = {} filter(hash_record(record)).each do |key, value| unless task['drop_columns'].find {|n| n == key } result[key] = value end end @page_builder.add(result.values) end end |
#finish ⇒ Object
46 47 48 |
# File 'lib/embulk/filter/script.rb', line 46 def finish @page_builder.finish end |