Class: Embulk::DataSource
Class Method Summary
collapse
Instance Method Summary
collapse
#convert!, #convert_key, included, #indifferent_access?, #indifferent_default, #indifferent_delete, #indifferent_fetch, #indifferent_key?, #indifferent_replace, #indifferent_update, #indifferent_value, #indifferent_values_at, #indifferent_writer, inject, inject!
Constructor Details
#initialize(hash = {}, default = nil, &block) ⇒ DataSource
Returns a new instance of DataSource.
130
131
132
133
134
135
136
137
|
# 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
|
Class Method Details
.from_java(java_data_source_impl) ⇒ Object
176
177
178
179
|
# File 'lib/embulk/data_source.rb', line 176
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
181
182
183
|
# File 'lib/embulk/data_source.rb', line 181
def self.from_ruby_hash(hash)
new.merge!(hash)
end
|
Instance Method Details
#load_config(task_type) ⇒ Object
190
191
192
|
# File 'lib/embulk/data_source.rb', line 190
def load_config(task_type)
Java::Injected::ModelManager.readObjectWithConfigSerDe(task_type.java_class, to_json.to_java)
end
|
#load_task(task_type) ⇒ Object
194
195
196
|
# File 'lib/embulk/data_source.rb', line 194
def load_task(task_type)
Java::Injected::ModelManager.readObject(task_type.java_class, to_json.to_java)
end
|
#param(key, type, options = {}) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# 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
Integer(v)
when :float
Float(v)
when :string
String(v).dup
when :bool
!!v
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 options.has_key?(:default)
value = options[:default]
else
raise "Required field #{key.to_s.dump} is not set"
end
return value
end
|
#to_java ⇒ Object
185
186
187
188
|
# File 'lib/embulk/data_source.rb', line 185
def to_java
json = to_json
Java::Injected::ModelManager.readObject(Java::DataSourceImpl.java_class, json.to_java)
end
|