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
196
197
198
199
|
# File 'lib/embulk/data_source.rb', line 196
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
201
202
203
|
# File 'lib/embulk/data_source.rb', line 201
def self.from_ruby_hash(hash)
new.merge!(hash)
end
|
Instance Method Details
#load_config(task_type) ⇒ Object
210
211
212
|
# File 'lib/embulk/data_source.rb', line 210
def load_config(task_type)
Java::Injected::ModelManager.readObjectWithConfigSerDe(task_type.java_class, to_json.to_java)
end
|
#load_task(task_type) ⇒ Object
214
215
216
|
# File 'lib/embulk/data_source.rb', line 214
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# 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, e
end
when :float
begin
Float(v)
rescue => e
raise ConfigError, e
end
when :string
begin
String(v).dup
rescue => e
raise ConfigError, e
end
when :bool
begin
!!v
rescue => e
raise ConfigError, e
end
when :hash
raise ConfigError, "Invalid value for :hash" unless v.is_a?(Hash)
DataSource.new.merge!(v)
when :array
raise ConfigError, "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, e
end
end
elsif options.has_key?(:default)
value = options[:default]
else
raise ConfigError, "Required field #{key.to_s.dump} is not set"
end
return value
end
|
#to_java ⇒ Object
205
206
207
208
|
# File 'lib/embulk/data_source.rb', line 205
def to_java
json = to_json
Java::Injected::ModelManager.readObject(Java::DataSourceImpl.java_class, json.to_java)
end
|