Class: TreasureData::Schema
- Inherits:
-
Object
- Object
- TreasureData::Schema
- Defined in:
- lib/td/client/model.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
- #add_field(name, type) ⇒ Array
- #from_json(obj) ⇒ self
-
#initialize(fields = []) ⇒ Schema
constructor
A new instance of Schema.
- #merge(schema) ⇒ Schema
- #to_json(*args) ⇒ Array<Field>
Constructor Details
#initialize(fields = []) ⇒ Schema
Returns a new instance of Schema.
312 313 314 |
# File 'lib/td/client/model.rb', line 312 def initialize(fields=[]) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
317 318 319 |
# File 'lib/td/client/model.rb', line 317 def fields @fields end |
Class Method Details
Instance Method Details
#add_field(name, type) ⇒ Array
322 323 324 |
# File 'lib/td/client/model.rb', line 322 def add_field(name, type) @fields << Field.new(name, type) end |
#from_json(obj) ⇒ self
347 348 349 350 351 352 |
# File 'lib/td/client/model.rb', line 347 def from_json(obj) @fields = obj.map {|f| Field.new(f[0], f[1]) } self end |
#merge(schema) ⇒ Schema
328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/td/client/model.rb', line 328 def merge(schema) nf = @fields.dup schema.fields.each {|f| if i = nf.find_index {|sf| sf.name == f.name } nf[i] = f else nf << f end } Schema.new(nf) end |
#to_json(*args) ⇒ Array<Field>
341 342 343 |
# File 'lib/td/client/model.rb', line 341 def to_json(*args) @fields.map {|f| [f.name, f.type] }.to_json(*args) end |