Class: ActiveRecord::ConnectionAdapters::Elasticsearch::TableMappingDefinition

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, AttributeMethods
Defined in:
lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb

Constant Summary collapse

ATTRIBUTES =
[:analyzer, :coerce, :copy_to, :doc_values, :dynamic, :eager_global_ordinals, :enabled,
:fielddata, :fields, :format, :ignore_above, :ignore_malformed, :index_options, :index_phrases,
:index_prefixes, :index, :meta, :normalizer, :norms, :null_value, :position_increment_gap,
:properties, :search_analyzer, :similarity, :subobjects, :store, :term_vector].freeze
ASSIGNABLE_ATTRIBUTES =

define virtual attributes, that must be assigned due a special logic

[:comment, :primary_key, :auto_increment, :meta].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, attributes) ⇒ TableMappingDefinition

INSTANCE METHODS #



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 43

def initialize(name, type, attributes)
  @name = name.to_sym

  attributes = attributes.symbolize_keys
  # directly set attributes, that cannot be assigned
  @attributes = attributes.except(*ASSIGNABLE_ATTRIBUTES)
  # assign special attributes
  __assign(attributes.slice(*ASSIGNABLE_ATTRIBUTES))

  @type = _resolve_type(type)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



27
28
29
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 27

def attributes
  @attributes
end

#nameObject

attributes



25
26
27
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 25

def name
  @name
end

#stateObject (readonly) Originally defined in module AttributeMethods

Returns the value of attribute state.

#typeObject

Returns the value of attribute type.



26
27
28
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 26

def type
  @type
end

Instance Method Details

#auto_incrementInteger

returns the +auto_increment+ value, if provided

Returns:

  • (Integer)


84
85
86
87
88
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 84

def auto_increment
  return nil unless _lazy_attributes[:auto_increment]
  return 0 if _lazy_attributes[:auto_increment] == true
  _lazy_attributes[:auto_increment].to_i
end

#auto_increment=(value) ⇒ Object

sets the +auto_increment+ as 'lazy_attribute'

Parameters:

  • value (Boolean, Integer)


98
99
100
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 98

def auto_increment=(value)
  _lazy_attributes[:auto_increment] = value
end

#auto_increment?Boolean

returns true if the +auto_increment+ 'attribute' was provided

Returns:

  • (Boolean)


92
93
94
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 92

def auto_increment?
  !!auto_increment
end

#commentString?

returns the +comment+ from 'meta' attribute

Returns:

  • (String, nil)


57
58
59
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 57

def comment
  __get_nested(:meta, :comment)
end

#comment=(value) ⇒ Object

sets the +comment+ as 'meta' attribute

Parameters:

  • value (String)


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

def comment=(value)
  # important: meta-values can only be strings!
  __set_nested(:meta, :comment, value.to_s)
end

#error_messagesObject Originally defined in module AttributeMethods

#metaHash

returns the meta hash

Returns:

  • (Hash)


104
105
106
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 104

def meta
  __get_attribute(:meta) || {}
end

#meta=(value) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 108

def meta=(value)
  if value.nil?
    __remove_attribute(:meta)
  else
    __set_attribute(:meta, value.compact)
  end
end

#primary_keyBoolean Also known as: primary_key?

returns true if the +primary_key+ 'attribute' was provided

Returns:

  • (Boolean)


70
71
72
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 70

def primary_key
  !!_lazy_attributes[:primary_key]
end

#primary_key=(value) ⇒ Object

sets the +primary_key+ as 'lazy_attribute'

Parameters:

  • value (Boolean)


78
79
80
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 78

def primary_key=(value)
  _lazy_attributes[:primary_key] = value
end

#state?Boolean Originally defined in module AttributeMethods

Returns:

  • (Boolean)

#with_state(state) ⇒ Object Originally defined in module AttributeMethods