Class: Ripple::Index

Inherits:
Object show all
Includes:
Translation
Defined in:
lib/ripple/indexes.rb

Overview

Represents a Secondary Index on a Document

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Translation

#i18n_scope

Constructor Details

#initialize(key, property_type, index_type = true) { ... } ⇒ Index

Creates an index for a Document

Parameters:

  • key (Symbol)

    the attribute key

  • property_type (Class)

    the type of the associated property

  • index_type ('bin', 'int', String, Integer) (defaults to: true)

    if given, the type of index

Yields:

  • a block that returns the value of the index



108
109
110
# File 'lib/ripple/indexes.rb', line 108

def initialize(key, property_type, index_type=true, &block)
  @key, @type, @index, @block = key, property_type, index_type, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



100
101
102
# File 'lib/ripple/indexes.rb', line 100

def block
  @block
end

#keyObject (readonly)

Returns the value of attribute key.



100
101
102
# File 'lib/ripple/indexes.rb', line 100

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



100
101
102
# File 'lib/ripple/indexes.rb', line 100

def type
  @type
end

Instance Method Details

#index_keyObject

The key under which a value will be indexed



114
115
116
# File 'lib/ripple/indexes.rb', line 114

def index_key
  "#{key}_#{index_type}"
end

#index_type"bin", ...

Returns the type of index used for this property.

Returns:

  • ("bin", "int", nil)

    the type of index used for this property

Raises:

  • (ArgumentError)

    if the type cannot be automatically determined



129
130
131
132
133
134
135
136
137
138
# File 'lib/ripple/indexes.rb', line 129

def index_type
  @index_type ||= case @index
                  when /^bin|int$/
                    @index
                  when Class
                    determine_index_type(@index)
                  else
                    determine_index_type(@type)
                  end
end

#to_index_value(value) ⇒ String, ...

Converts an attribute to a value appropriate for storing in a secondary index.

Parameters:

Returns:

  • (String, Integer, Set)

    a value appropriate for storing in a secondary index



123
124
125
# File 'lib/ripple/indexes.rb', line 123

def to_index_value(value)
  value.to_ripple_index(index_type)
end