Class: ActiveRecord::ConnectionAdapters::Elasticsearch::TableMappingDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Elasticsearch::TableMappingDefinition
- Includes:
- ActiveModel::Validations, AttributeMethods
- Defined in:
- lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb
Constant Summary collapse
- ATTRIBUTES =
available mapping properties
[: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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
attributes.
-
#state ⇒ Object
included
from AttributeMethods
readonly
Returns the value of attribute state.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#auto_increment ⇒ Integer
returns the +auto_increment+ value, if provided.
-
#auto_increment=(value) ⇒ Object
sets the +auto_increment+ as 'lazy_attribute'.
-
#auto_increment? ⇒ Boolean
returns true if the +auto_increment+ 'attribute' was provided.
-
#comment ⇒ String?
returns the +comment+ from 'meta' attribute.
-
#comment=(value) ⇒ Object
sets the +comment+ as 'meta' attribute.
- #error_messages ⇒ Object included from AttributeMethods
-
#initialize(name, type, attributes) ⇒ TableMappingDefinition
constructor
INSTANCE METHODS #.
-
#meta ⇒ Hash
returns the meta hash.
- #meta=(value) ⇒ Object
-
#primary_key ⇒ Boolean
(also: #primary_key?)
returns true if the +primary_key+ 'attribute' was provided.
-
#primary_key=(value) ⇒ Object
sets the +primary_key+ as 'lazy_attribute'.
- #state? ⇒ Boolean included from AttributeMethods
- #with_state(state) ⇒ Object included from AttributeMethods
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
#attributes ⇒ Object
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 |
#name ⇒ Object
attributes
25 26 27 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 25 def name @name end |
#state ⇒ Object (readonly) Originally defined in module AttributeMethods
Returns the value of attribute state.
#type ⇒ Object
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_increment ⇒ Integer
returns the +auto_increment+ value, if provided
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'
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
92 93 94 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 92 def auto_increment? !!auto_increment end |
#comment ⇒ String?
returns the +comment+ from 'meta' attribute
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
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_messages ⇒ Object Originally defined in module AttributeMethods
#meta ⇒ Hash
returns the meta hash
104 105 106 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/table_mapping_definition.rb', line 104 def __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 (value) if value.nil? __remove_attribute(:meta) else __set_attribute(:meta, value.compact) end end |
#primary_key ⇒ Boolean Also known as: primary_key?
returns true if the +primary_key+ 'attribute' was provided
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'
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 |