Class: Embulk::DataSource
- Inherits:
-
Hash
- Object
- Hash
- Embulk::DataSource
- Defined in:
- lib/embulk/data_source.rb
Class Method Summary collapse
Instance Method Summary collapse
- #load_config(task_type) ⇒ Object
- #load_task(task_type) ⇒ Object
- #param(key, type, options = {}) ⇒ Object
- #to_java ⇒ Object
Class Method Details
.from_java(java_data_source_impl) ⇒ Object
42 43 44 45 |
# File 'lib/embulk/data_source.rb', line 42 def self.from_java(java_data_source_impl) json = java_data_source_impl.toString new.merge!(JSON.parse(json)) end |
.from_ruby_hash(hash) ⇒ Object
47 48 49 |
# File 'lib/embulk/data_source.rb', line 47 def self.from_ruby_hash(hash) new.merge!(hash) end |
Instance Method Details
#load_config(task_type) ⇒ Object
56 57 58 |
# File 'lib/embulk/data_source.rb', line 56 def load_config(task_type) Java::Injected::ModelManager.readObjectWithConfigSerDe(task_type.java_class, to_json.to_java) end |
#load_task(task_type) ⇒ Object
60 61 62 |
# File 'lib/embulk/data_source.rb', line 60 def load_task(task_type) Java::Injected::ModelManager.readObject(task_type.java_class, to_json.to_java) end |
#param(key, type, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/embulk/data_source.rb', line 5 def param(key, type, ={}) if self.has_key?(key) v = self[key] value = case type when :integer Integer(v) when :float Float(v) when :string String(v).dup when :bool !!v # TODO validation when :hash raise ArgumentError, "Invalid value for :hash" unless v.is_a?(Hash) DataSource.new.merge!(v) when :array raise ArgumentError, "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 type.load(v) end elsif .has_key?(:default) value = [:default] else raise "Required field #{key.to_s.dump} is not set" end return value end |
#to_java ⇒ Object
51 52 53 54 |
# File 'lib/embulk/data_source.rb', line 51 def to_java json = to_json Java::Injected::ModelManager.readObject(Java::DataSourceImpl.java_class, json.to_java) end |