Class: Airtable::Field

Inherits:
Resource show all
Defined in:
lib/airtable/field.rb

Overview

Object corresponding to an Airtable Field

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #token

Instance Method Summary collapse

Methods inherited from Resource

#check_and_raise_error

Constructor Details

#initialize(token, table, id, data = nil) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
12
13
14
15
# File 'lib/airtable/field.rb', line 7

def initialize(token, table, id, data = nil)
  super(token)
  @table = table
  @base = @table.base
  @id = id
  data&.each_key do |key|
    instance_variable_set(:"@#{key}", data[key])
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'lib/airtable/field.rb', line 5

def base
  @base
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/airtable/field.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/airtable/field.rb', line 5

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/airtable/field.rb', line 5

def table
  @table
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/airtable/field.rb', line 5

def type
  @type
end

Instance Method Details

#field_urlObject (protected)

Endpoint for tables



31
# File 'lib/airtable/field.rb', line 31

def field_url = "/v0/meta/bases/#{@base.id}/tables/#{@table.id}/fields/#{@id}"

#update(field_data) ⇒ Airtable::Field



19
20
21
22
23
24
25
26
# File 'lib/airtable/field.rb', line 19

def update(field_data)
  response = self.class.patch(field_url,
                              body: field_data.to_json).parsed_response

  check_and_raise_error(response)

  Airtable::Field.new(@token, @table, response)
end