Class: Dynamoid::Indexes::Index
- Inherits:
-
Object
- Object
- Dynamoid::Indexes::Index
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/dynamoid/indexes.rb
Overview
Represents the attributes of a DynamoDB index.
Constant Summary collapse
- PROJECTION_TYPES =
%i[keys_only all].to_set
- DEFAULT_PROJECTION_TYPE =
:keys_only
Instance Attribute Summary collapse
-
#dynamoid_class ⇒ Object
Returns the value of attribute dynamoid_class.
-
#hash_key ⇒ Object
Returns the value of attribute hash_key.
-
#hash_key_schema ⇒ Object
Returns the value of attribute hash_key_schema.
-
#name ⇒ Object
Returns the value of attribute name.
-
#projected_attributes ⇒ Object
Returns the value of attribute projected_attributes.
-
#range_key ⇒ Object
Returns the value of attribute range_key.
-
#range_key_schema ⇒ Object
Returns the value of attribute range_key_schema.
-
#read_capacity ⇒ Object
Returns the value of attribute read_capacity.
-
#type ⇒ Object
Returns the value of attribute type.
-
#write_capacity ⇒ Object
Returns the value of attribute write_capacity.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Index
constructor
A new instance of Index.
-
#projection_type ⇒ Symbol
Convenience method to determine the projection type for an index.
Constructor Details
#initialize(attrs = {}) ⇒ Index
Returns a new instance of Index.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/dynamoid/indexes.rb', line 254 def initialize(attrs = {}) unless attrs[:dynamoid_class].present? raise Dynamoid::Errors::InvalidIndex, ':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, self unless valid? end |
Instance Attribute Details
#dynamoid_class ⇒ Object
Returns the value of attribute dynamoid_class.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def dynamoid_class @dynamoid_class end |
#hash_key ⇒ Object
Returns the value of attribute hash_key.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def hash_key @hash_key end |
#hash_key_schema ⇒ Object
Returns the value of attribute hash_key_schema.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def hash_key_schema @hash_key_schema end |
#name ⇒ Object
Returns the value of attribute name.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def name @name end |
#projected_attributes ⇒ Object
Returns the value of attribute projected_attributes.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def projected_attributes @projected_attributes end |
#range_key ⇒ Object
Returns the value of attribute range_key.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def range_key @range_key end |
#range_key_schema ⇒ Object
Returns the value of attribute range_key_schema.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def range_key_schema @range_key_schema end |
#read_capacity ⇒ Object
Returns the value of attribute read_capacity.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def read_capacity @read_capacity end |
#type ⇒ Object
Returns the value of attribute type.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def type @type end |
#write_capacity ⇒ Object
Returns the value of attribute write_capacity.
243 244 245 |
# File 'lib/dynamoid/indexes.rb', line 243 def write_capacity @write_capacity end |
Instance Method Details
#projection_type ⇒ Symbol
Convenience method to determine the projection type for an index. Projection types are: :keys_only, :all, :include.
276 277 278 279 280 281 282 |
# File 'lib/dynamoid/indexes.rb', line 276 def projection_type if @projected_attributes.is_a? Array :include else @projected_attributes end end |