Class: BigIndex::IndexField

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/big_index/index_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_kind_of

Constructor Details

#initialize(params, block = nil) ⇒ IndexField

Returns a new instance of IndexField.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/big_index/index_field.rb', line 10

def initialize(params, block = nil)
  raise "IndexField requires at least a field name" unless params.size > 0

  @params = params.dup
  @block = block

  @field_name = params.shift
  assert_kind_of 'field_name', @field_name, Symbol, String

  unless params.empty? || ![Symbol, String].include?(params.first.class)
    @field_type = params.shift
  end

  @options = params.shift || {}
  assert_kind_of 'options', @options, Hash

  # Setting the default values
  @options[:finder_name] ||= field_name
  @field_type ||= :text
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



35
36
37
# File 'lib/big_index/index_field.rb', line 35

def method_missing(name)
  @options[name.to_sym] || super
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



8
9
10
# File 'lib/big_index/index_field.rb', line 8

def block
  @block
end

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/big_index/index_field.rb', line 8

def field
  @field
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



8
9
10
# File 'lib/big_index/index_field.rb', line 8

def field_name
  @field_name
end

#field_typeObject (readonly)

Returns the value of attribute field_type.



8
9
10
# File 'lib/big_index/index_field.rb', line 8

def field_type
  @field_type
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/big_index/index_field.rb', line 8

def options
  @options
end

Instance Method Details

#[](name) ⇒ Object



31
32
33
# File 'lib/big_index/index_field.rb', line 31

def [](name)
  @options[name]
end