Class: AwsRecord::Generators::SecondaryIndex
- Inherits:
-
Object
- Object
- AwsRecord::Generators::SecondaryIndex
- Defined in:
- lib/generators/aws_record/secondary_index.rb
Constant Summary collapse
- PROJ_TYPES =
%w[ALL KEYS_ONLY INCLUDE].freeze
Instance Attribute Summary collapse
-
#hash_key ⇒ Object
readonly
Returns the value of attribute hash_key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#projection_type ⇒ Object
readonly
Returns the value of attribute projection_type.
-
#range_key ⇒ Object
readonly
Returns the value of attribute range_key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, opts) ⇒ SecondaryIndex
constructor
A new instance of SecondaryIndex.
Constructor Details
#initialize(name, opts) ⇒ SecondaryIndex
Returns a new instance of SecondaryIndex.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/aws_record/secondary_index.rb', line 40 def initialize(name, opts) raise ArgumentError, 'You must provide a name' unless name raise ArgumentError, 'You must provide a hash key' unless opts[:hash_key] if opts.key? :projection_type unless PROJ_TYPES.include? opts[:projection_type] raise ArgumentError, "Invalid projection type #{opts[:projection_type]}" end if opts[:projection_type] != 'ALL' raise NotImplementedError, 'ALL is the only projection type currently supported' end else opts[:projection_type] = 'ALL' end if opts[:hash_key] == opts[:range_key] raise ArgumentError, "#{opts[:hash_key]} cannot be both the rkey and hkey for gsi #{name}" end @name = name @hash_key = opts[:hash_key] @range_key = opts[:range_key] @projection_type = "\"#{opts[:projection_type]}\"" end |
Instance Attribute Details
#hash_key ⇒ Object (readonly)
Returns the value of attribute hash_key.
7 8 9 |
# File 'lib/generators/aws_record/secondary_index.rb', line 7 def hash_key @hash_key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/generators/aws_record/secondary_index.rb', line 7 def name @name end |
#projection_type ⇒ Object (readonly)
Returns the value of attribute projection_type.
7 8 9 |
# File 'lib/generators/aws_record/secondary_index.rb', line 7 def projection_type @projection_type end |
#range_key ⇒ Object (readonly)
Returns the value of attribute range_key.
7 8 9 |
# File 'lib/generators/aws_record/secondary_index.rb', line 7 def range_key @range_key end |
Class Method Details
.parse(key_definition) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/generators/aws_record/secondary_index.rb', line 10 def parse(key_definition) name, = key_definition.split(':') = .split(',') if opts = () new(name, opts) end |