Class: AwsRecord::Generators::SecondaryIndex Private

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/secondary_index.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

PROJ_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[ALL KEYS_ONLY INCLUDE].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts) ⇒ SecondaryIndex

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SecondaryIndex.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/generators/secondary_index.rb', line 41

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_keyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/generators/secondary_index.rb', line 8

def hash_key
  @hash_key
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/generators/secondary_index.rb', line 8

def name
  @name
end

#projection_typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/generators/secondary_index.rb', line 8

def projection_type
  @projection_type
end

#range_keyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/generators/secondary_index.rb', line 8

def range_key
  @range_key
end

Class Method Details

.parse(key_definition) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
# File 'lib/generators/secondary_index.rb', line 11

def parse(key_definition)
  name, index_options = key_definition.split(':')
  index_options = index_options.split(',') if index_options
  opts = parse_raw_options(index_options)

  new(name, opts)
end