class Embulk::Input::Inline
Public Class Methods
resume(task, columns, count) { |task, columns, count| ... }
click to toggle source
# File lib/embulk/input/inline.rb, line 20 def self.resume(task, columns, count, &control) task_reports = yield(task, columns, count) next_config_diff = {} return next_config_diff end
transaction(config, &control)
click to toggle source
# File lib/embulk/input/inline.rb, line 7 def self.transaction(config, &control) task = { "schema" => config.param("schema", :array), "data" => config.param("data", :array) } columns = task['schema'].map.with_index { |column, i| Column.new(i, column['name'], column['type'].to_sym) } resume(task, columns, 1, &control) end
Public Instance Methods
init()
click to toggle source
# File lib/embulk/input/inline.rb, line 27 def init @data = task["data"] end
run()
click to toggle source
# File lib/embulk/input/inline.rb, line 31 def run @data.each do |record| values = schema.map { |column| convert_value(column.type, record[column.name]) } page_builder.add(values) end page_builder.finish task_report = {} return task_report end
Private Instance Methods
convert_value(type, value)
click to toggle source
# File lib/embulk/input/inline.rb, line 46 def convert_value(type, value) return nil if value.nil? case type when :string value when :long value.to_i when :double value.to_f when :boolean if value.is_a?(TrueClass) || value.is_a?(FalseClass) value else downcased_val = value.downcase case downcased_val when 'true' then true when 'false' then false when '1' then true when '0' then false else nil end end when :timestamp Time.parse(value) when :json value else raise "Unsupported type #{field['type']}" end end