Class: AwsRecord::Generators::SecondaryIndex

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

Constant Summary collapse

PROJ_TYPES =
%w(ALL KEYS_ONLY INCLUDE)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts) ⇒ SecondaryIndex

Returns a new instance of SecondaryIndex.

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/aws_record/secondary_index.rb', line 38

def initialize(name, opts)
  raise ArgumentError.new("You must provide a name") if not name
  raise ArgumentError.new("You must provide a hash key") if not opts[:hash_key]

  if opts.key? :projection_type
    raise ArgumentError.new("Invalid projection type #{opts[:projection_type]}") if not PROJ_TYPES.include? opts[:projection_type]
    raise NotImplementedError.new("ALL is the only projection type currently supported") if opts[:projection_type] != "ALL"
  else
    opts[:projection_type] = "ALL"
  end

  if opts[:hash_key] == opts[:range_key]
    raise ArgumentError.new("#{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)

Returns the value of attribute hash_key.



6
7
8
# File 'lib/generators/aws_record/secondary_index.rb', line 6

def hash_key
  @hash_key
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/generators/aws_record/secondary_index.rb', line 6

def name
  @name
end

#projection_typeObject (readonly)

Returns the value of attribute projection_type.



6
7
8
# File 'lib/generators/aws_record/secondary_index.rb', line 6

def projection_type
  @projection_type
end

#range_keyObject (readonly)

Returns the value of attribute range_key.



6
7
8
# File 'lib/generators/aws_record/secondary_index.rb', line 6

def range_key
  @range_key
end

Class Method Details

.parse(key_definition) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/generators/aws_record/secondary_index.rb', line 9

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