class Embulk::DataSource

Public Class Methods

from_java(java_data_source_impl) click to toggle source
# File lib/embulk/data_source.rb, line 195
def self.from_java(java_data_source_impl)
  json = java_data_source_impl.toString
  new.merge!(JSON.parse(json))
end
from_ruby_hash(hash) click to toggle source
# File lib/embulk/data_source.rb, line 200
def self.from_ruby_hash(hash)
  new.merge!(hash)
end
new(hash={}, default=nil, &block) click to toggle source
Calls superclass method
# File lib/embulk/data_source.rb, line 130
def initialize(hash={}, default=nil, &block)
  if default.nil?
    super(&block)
  else
    super(default)
  end
  hash.each {|key,value| self[key] = value }
end

Public Instance Methods

load_config(task_type) click to toggle source
# File lib/embulk/data_source.rb, line 209
def load_config(task_type)
  Java::Injected::ModelManager.readObjectWithConfigSerDe(task_type.java_class, to_json.to_java)
end
load_task(task_type) click to toggle source
# File lib/embulk/data_source.rb, line 213
def load_task(task_type)
  Java::Injected::ModelManager.readObject(task_type.java_class, to_json.to_java)
end
param(key, type, options={}) click to toggle source
# File lib/embulk/data_source.rb, line 139
def param(key, type, options={})
  if self.has_key?(key)
    v = self[key]
    value =
      case type
      when :integer
        begin
          Integer(v)
        rescue => e
          raise ConfigError.new e
        end
      when :float
        begin
          Float(v)
        rescue => e
          raise ConfigError.new e
        end
      when :string
        begin
          String(v).dup
        rescue => e
          raise ConfigError.new e
        end
      when :bool
        begin
          !!v  # TODO validation
        rescue => e
          raise ConfigError.new e
        end
      when :hash
        raise ConfigError.new "Invalid value for :hash" unless v.is_a?(Hash)
        DataSource.new.merge!(v)
      when :array
        raise ConfigError.new "Invalid value for :array" unless v.is_a?(Array)
        v.dup
      else
        unless type.respond_to?(:load)
          raise ArgumentError, "Unknown type #{type.to_s.dump}"
        end
        begin
          type.load(v)
        rescue => e
          raise ConfigError.new e
        end
      end

  elsif options.has_key?(:default)
    value = options[:default]

  else
    raise ConfigError.new "Required field #{key.to_s.dump} is not set"
  end

  return value
end
to_java() click to toggle source
# File lib/embulk/data_source.rb, line 204
def to_java
  json = to_json
  Java::Injected::ModelManager.readObject(Java::DataSourceImpl.java_class, json.to_java)
end