Class: ActiveRecord::ConnectionAdapters::Elasticsearch::Column

Inherits:
ConnectionAdapters::Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/elasticsearch/column.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type_metadata = nil, virtual: false, fields: nil, properties: nil, meta: nil, enabled: nil, **kwargs) ⇒ Column

Returns a new instance of Column.



10
11
12
13
14
15
16
17
18
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 10

def initialize(name, default,  = nil, virtual: false, fields: nil, properties: nil, meta: nil, enabled: nil, **kwargs)
  @virtual    = virtual
  @fields     = fields.presence || []
  @properties = properties.presence || []
  @meta       = meta.presence || {}
  @enabled    = enabled.nil? ? true : enabled

  super(name, default, , true, nil, **kwargs)
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled.



8
9
10
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 8

def enabled
  @enabled
end

#fieldsObject (readonly)

Returns the value of attribute fields.



8
9
10
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 8

def fields
  @fields
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 8

def meta
  @meta
end

#propertiesObject (readonly)

Returns the value of attribute properties.



8
9
10
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 8

def properties
  @properties
end

#virtualObject (readonly)

Returns the value of attribute virtual.



8
9
10
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 8

def virtual
  @virtual
end

Instance Method Details

#commentObject

returns comment from meta



21
22
23
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 21

def comment
  meta? && meta['comment']
end

#enabled?Boolean

returns true if this column is enabled (= searchable by queries)

Returns:

  • (Boolean)


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

def enabled?
  !!enabled
end

#field_namesArray

returns a array of field names

Returns:

  • (Array)


61
62
63
64
65
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 61

def field_names
  return [] unless fields?

  fields.map { |field| field['name'] }
end

#fields?Boolean

returns true if this column has nested fields To receive the nested names just call +#fields+ on this object.

Returns:

  • (Boolean)


48
49
50
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 48

def fields?
  fields.present?
end

#meta?Boolean

returns true if this column has meta information To receive the nested meta-data just call +#meta+ on this object.

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 41

def meta?
  meta.present?
end

#properties?Boolean

returns true if this column has nested properties To receive the nested names just call +#properties+ on this object.

Returns:

  • (Boolean)


55
56
57
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 55

def properties?
  properties.present?
end

#property_namesArray

returns a array of property names

Returns:

  • (Array)


69
70
71
72
73
# File 'lib/active_record/connection_adapters/elasticsearch/column.rb', line 69

def property_names
  return [] unless properties?

  properties.map { |property| property['name'] }
end

#virtual?Boolean

returns true if this column is virtual. Virtual columns cannot be saved.

Returns:

  • (Boolean)


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

def virtual?
  !!virtual
end