Class: Appfuel::Dynamodb::PrimaryKey

Inherits:
Object
  • Object
show all
Defined in:
lib/appfuel/storage/dynamodb/primary_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_key, hash_type, range_key = nil, range_type = nil) ⇒ PrimaryKey

Returns a new instance of PrimaryKey.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/appfuel/storage/dynamodb/primary_key.rb', line 6

def initialize(hash_key, hash_type, range_key = nil, range_type = nil)
  @hash_key = hash_key.to_sym
  @hash_type = hash_type
  unless range_key.nil?
    if range_type.nil?
      fail "range_type is required for primary range key"
    end
    @range_key = range_key
    @range_type = range_type
  end
end

Instance Attribute Details

#hash_keyObject (readonly)

Returns the value of attribute hash_key.



4
5
6
# File 'lib/appfuel/storage/dynamodb/primary_key.rb', line 4

def hash_key
  @hash_key
end

#range_keyObject (readonly)

Returns the value of attribute range_key.



4
5
6
# File 'lib/appfuel/storage/dynamodb/primary_key.rb', line 4

def range_key
  @range_key
end

Instance Method Details

#composite?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/appfuel/storage/dynamodb/primary_key.rb', line 18

def composite?
  !range_key.nil?
end

#params(hash_value, range_value = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/appfuel/storage/dynamodb/primary_key.rb', line 22

def params(hash_value, range_value = nil)
  data = { hash_key => hash_value }
  if composite?
    if range_value.nil?
      fail "This is a composite key range_value is required"
    end
    data[range_key] = range_value
  end
  data
end