Class: ActiveRecord::ConnectionAdapters::Elasticsearch::TableDefinition

Inherits:
Object
  • Object
show all
Includes:
ColumnMethods
Defined in:
lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, name, **opts) ⇒ TableDefinition

Returns a new instance of TableDefinition.



22
23
24
25
26
27
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 22

def initialize(conn, name, **opts)
  @conn   = conn
  @name   = name
  @opts   = opts
  @failed = false
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



18
19
20
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 18

def conn
  @conn
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 19

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



20
21
22
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 20

def opts
  @opts
end

Instance Method Details

#assignObject

yields provided block with self to change the table and collect table information returns self, to chain this method



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 31

def assign
  # if before assign fails, we don't want to continue yielding!
  _before_assign

  begin
    yield self
  rescue => e
    @failed = false
    _rescue_assign
    raise e
  end

  _after_assign
end

#exec!Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 46

def exec!
  # if before exec fails, we don't want to continue with execution!
  _before_exec

  begin
    _exec
  rescue => e
    @failed = false
    _rescue_exec
    raise e
  end

  _after_exec
end

#failed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_definition.rb', line 61

def failed?
  @failed
end

#primary_key(name, type = :primary_key, **options) ⇒ Object Originally defined in module ColumnMethods

Appends a primary key definition to the table definition. Can be called multiple times, but this is probably not a good idea.