Class: AgnosticBackend::Indexable::FieldType

Inherits:
Object
  • Object
show all
Defined in:
lib/agnostic_backend/indexable/field_type.rb

Constant Summary collapse

INTEGER =
:integer
DOUBLE =
:double
STRING =

literal string (i.e. should be matched exactly)

:string
STRING_ARRAY =
:string_array
TEXT =
:text
TEXT_ARRAY =
:text_array
DATE =

datetime

:date
BOOLEAN =
:boolean
STRUCT =

a nested structure containing other values

:struct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, **options) ⇒ FieldType

Returns a new instance of FieldType.



24
25
26
27
28
# File 'lib/agnostic_backend/indexable/field_type.rb', line 24

def initialize(type, **options)
  raise "Type #{type} not supported" unless FieldType.exists? type
  @type = type
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/agnostic_backend/indexable/field_type.rb', line 22

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/agnostic_backend/indexable/field_type.rb', line 22

def type
  @type
end

Class Method Details

.allObject



14
15
16
# File 'lib/agnostic_backend/indexable/field_type.rb', line 14

def self.all
  constants.map { |constant| const_get(constant) }
end

.exists?(type) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/agnostic_backend/indexable/field_type.rb', line 18

def self.exists?(type)
  all.include? type
end

Instance Method Details

#get_option(option_name) ⇒ Object



38
39
40
# File 'lib/agnostic_backend/indexable/field_type.rb', line 38

def get_option(option_name)
  @options[option_name.to_sym]
end

#has_option(option_name) ⇒ Object



42
43
44
# File 'lib/agnostic_backend/indexable/field_type.rb', line 42

def has_option(option_name)
  @options.has_key? option_name.to_sym
end

#matches?(type) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/agnostic_backend/indexable/field_type.rb', line 34

def matches?(type)
  self.type == type
end

#nested?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/agnostic_backend/indexable/field_type.rb', line 30

def nested?
  type == STRUCT
end