Class: ActiveRecord::ConnectionAdapters::Elasticsearch::CloneTableDefinition

Inherits:
TableDefinition
  • Object
show all
Defined in:
lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, name, target, settings: nil, aliases: nil, **opts) ⇒ CloneTableDefinition

Returns a new instance of CloneTableDefinition.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 12

def initialize(conn, name, target, settings: nil, aliases: nil, **opts)
  super(conn, name, **opts)

  @target   = target
  @settings = HashWithIndifferentAccess.new
  @aliases  = HashWithIndifferentAccess.new

  # before assigning new settings, we need to resolve some defaults
  assign_default_clone_settings!

  transform_settings!(settings) if settings.present?
  transform_aliases!(aliases) if aliases.present?
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 10

def target
  @target
end

Instance Method Details

#alias(name, force: false, **options, &block) ⇒ Object

we can use +alias+ here, since the instance method is not a reserved keyword!

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 56

def alias(name, force: false, **options, &block)
  raise ArgumentError, "you cannot define an already defined alias '#{name}'." if @aliases.key?(name) && !force?(force)

  @aliases[name] = new_alias_definition(name, **options, &block)

  self
end

#aliasesArray

returns an array with all +TableAliasDefinition+.

Returns:

  • (Array)


34
35
36
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 34

def aliases
  @aliases.values
end

#remove_alias(name) ⇒ Object



64
65
66
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 64

def remove_alias(name)
  @aliases.delete name
end

#remove_setting(name) ⇒ Object



50
51
52
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 50

def remove_setting(name)
  @settings.delete name
end

#setting(name, value, force: false, **options, &block) ⇒ Object

DEFINITION METHODS #

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 42

def setting(name, value, force: false, **options, &block)
  raise ArgumentError, "you cannot define an already defined setting '#{name}'!" if @settings.key?(name) && !force?(force)

  @settings[name] = new_setting_definition(name, value, **options, &block)

  self
end

#settingsArray

returns an array with all +TableSettingDefinition+.

Returns:

  • (Array)


28
29
30
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/clone_table_definition.rb', line 28

def settings
  @settings.values
end