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



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

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



279
280
281
# File 'lib/google/cloud/bigquery/schema.rb', line 279

def description
  @gapi.description
end

#description=(new_description) ⇒ Object



283
284
285
# File 'lib/google/cloud/bigquery/schema.rb', line 283

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

#fieldsObject



295
296
297
# File 'lib/google/cloud/bigquery/schema.rb', line 295

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

#fields=(new_fields) ⇒ Object



299
300
301
# File 'lib/google/cloud/bigquery/schema.rb', line 299

def fields= new_fields
  @fields = new_fields
end

#modeObject



287
288
289
# File 'lib/google/cloud/bigquery/schema.rb', line 287

def mode
  @gapi.mode
end

#mode=(new_mode) ⇒ Object



291
292
293
# File 'lib/google/cloud/bigquery/schema.rb', line 291

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

#nameObject



263
264
265
# File 'lib/google/cloud/bigquery/schema.rb', line 263

def name
  @gapi.name
end

#name=(new_name) ⇒ Object



267
268
269
# File 'lib/google/cloud/bigquery/schema.rb', line 267

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

#typeObject



271
272
273
# File 'lib/google/cloud/bigquery/schema.rb', line 271

def type
  @gapi.type
end

#type=(new_type) ⇒ Object



275
276
277
# File 'lib/google/cloud/bigquery/schema.rb', line 275

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