Class: Dynamoid::Indexes::Index

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/dynamoid/indexes.rb

Overview

Represents the attributes of a DynamoDB index.

Constant Summary collapse

PROJECTION_TYPES =
[:keys_only, :all].to_set
DEFAULT_PROJECTION_TYPE =
:keys_only

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Index

Returns a new instance of Index.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/dynamoid/indexes.rb', line 179

def initialize(attrs={})
  unless attrs[:dynamoid_class].present?
    raise Dynamoid::Errors::InvalidIndex.new(':dynamoid_class is required')
  end

  @dynamoid_class = attrs[:dynamoid_class]
  @type = attrs[:type]
  @hash_key = attrs[:hash_key]
  @range_key = attrs[:range_key]
  @name = attrs[:name] || @dynamoid_class.index_name(@hash_key, @range_key)
  @projected_attributes =
      attrs[:projected_attributes] || DEFAULT_PROJECTION_TYPE
  @read_capacity = attrs[:read_capacity]
  @write_capacity = attrs[:write_capacity]

  raise Dynamoid::Errors::InvalidIndex.new(self) unless self.valid?
end

Instance Attribute Details

#dynamoid_classObject

Returns the value of attribute dynamoid_class.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def dynamoid_class
  @dynamoid_class
end

#hash_keyObject

Returns the value of attribute hash_key.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def hash_key
  @hash_key
end

#hash_key_schemaObject

Returns the value of attribute hash_key_schema.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def hash_key_schema
  @hash_key_schema
end

#nameObject

Returns the value of attribute name.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def name
  @name
end

#projected_attributesObject

Returns the value of attribute projected_attributes.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def projected_attributes
  @projected_attributes
end

#range_keyObject

Returns the value of attribute range_key.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def range_key
  @range_key
end

#range_key_schemaObject

Returns the value of attribute range_key_schema.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def range_key_schema
  @range_key_schema
end

#read_capacityObject

Returns the value of attribute read_capacity.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def read_capacity
  @read_capacity
end

#typeObject

Returns the value of attribute type.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def type
  @type
end

#write_capacityObject

Returns the value of attribute write_capacity.



168
169
170
# File 'lib/dynamoid/indexes.rb', line 168

def write_capacity
  @write_capacity
end

Instance Method Details

#projection_typeSymbol

Convenience method to determine the projection type for an index. Projection types are: :keys_only, :all, :include.

Returns:

  • (Symbol)

    the projection type.



201
202
203
204
205
206
207
# File 'lib/dynamoid/indexes.rb', line 201

def projection_type
  if @projected_attributes.is_a? Array
    :include
  else
    @projected_attributes
  end
end