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
DATE_ARRAY =

datetime

:date_array
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.



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

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.



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

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.allObject



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

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

.exists?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#get_option(option_name) ⇒ Object



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

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

#has_option(option_name) ⇒ Object



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

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

#matches?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#nested?Boolean

Returns:

  • (Boolean)


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

def nested?
  type == STRUCT
end