Class: Google::Cloud::Bigquery::Schema::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigquery/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, type, description: nil, mode: :nullable, fields: nil) ⇒ Field

Returns a new instance of Field



247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/google/cloud/bigquery/schema.rb', line 247

def initialize name, type, description: nil,
               mode: :nullable, fields: nil
  @gapi = Google::Apis::BigqueryV2::TableFieldSchema.new
  @gapi.update! name: name
  @gapi.update! type: verify_type(type)
  @gapi.update! description: description if description
  @gapi.update! mode: verify_mode(mode) if mode
  if fields
    @fields = fields
    check_for_changed_fields!
  end
  @original_json = @gapi.to_json
end

Instance Method Details

#descriptionObject



277
278
279
# File 'lib/google/cloud/bigquery/schema.rb', line 277

def description
  @gapi.description
end

#description=(new_description) ⇒ Object



281
282
283
# File 'lib/google/cloud/bigquery/schema.rb', line 281

def description= new_description
  @gapi.update! description: new_description
end

#fieldsObject



293
294
295
# File 'lib/google/cloud/bigquery/schema.rb', line 293

def fields
  @fields ||= Array(@gapi.fields).map { |f| Field.from_gapi f }
end

#fields=(new_fields) ⇒ Object



297
298
299
# File 'lib/google/cloud/bigquery/schema.rb', line 297

def fields= new_fields
  @fields = new_fields
end

#modeObject



285
286
287
# File 'lib/google/cloud/bigquery/schema.rb', line 285

def mode
  @gapi.mode
end

#mode=(new_mode) ⇒ Object



289
290
291
# File 'lib/google/cloud/bigquery/schema.rb', line 289

def mode= new_mode
  @gapi.update! mode: verify_mode(new_mode)
end

#nameObject



261
262
263
# File 'lib/google/cloud/bigquery/schema.rb', line 261

def name
  @gapi.name
end

#name=(new_name) ⇒ Object



265
266
267
# File 'lib/google/cloud/bigquery/schema.rb', line 265

def name= new_name
  @gapi.update! name: new_name
end

#typeObject



269
270
271
# File 'lib/google/cloud/bigquery/schema.rb', line 269

def type
  @gapi.type
end

#type=(new_type) ⇒ Object



273
274
275
# File 'lib/google/cloud/bigquery/schema.rb', line 273

def type= new_type
  @gapi.update! type: verify_type(new_type)
end