Class: FakeDynamo::Key
- Inherits:
-
Object
show all
- Extended by:
- Validation
- Includes:
- Comparable
- Defined in:
- lib/fake_dynamo/key.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Validation
add_errors, api_config, api_config_path, api_input_spec, available_operations, param, validate!, validate_input, validate_key_data, validate_key_schema, validate_operation, validate_payload, validate_request_size, validate_spec, validate_type
Instance Attribute Details
#primary ⇒ Object
Returns the value of attribute primary.
6
7
8
|
# File 'lib/fake_dynamo/key.rb', line 6
def primary
@primary
end
|
#range ⇒ Object
Returns the value of attribute range.
6
7
8
|
# File 'lib/fake_dynamo/key.rb', line 6
def range
@range
end
|
Class Method Details
.create_attribute(key, data) ⇒ Object
31
32
33
34
35
|
# File 'lib/fake_dynamo/key.rb', line 31
def create_attribute(key, data)
name = key.name
attr = Attribute.from_hash(name, data[name])
attr
end
|
.from_data(key_data, key_schema) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/fake_dynamo/key.rb', line 9
def from_data(key_data, key_schema)
key = Key.new
validate_key_data(key_data, key_schema)
key.primary = Attribute.from_hash(key_schema.hash_key.name, key_data['HashKeyElement'])
if key_schema.range_key
key.range = Attribute.from_hash(key_schema.range_key.name, key_data['RangeKeyElement'])
end
key
end
|
.from_schema(data, key_schema) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fake_dynamo/key.rb', line 20
def from_schema(data, key_schema)
key = Key.new
validate_key_schema(data, key_schema)
key.primary = create_attribute(key_schema.hash_key, data)
if key_schema.range_key
key.range = create_attribute(key_schema.range_key, data)
end
key
end
|
Instance Method Details
#<=>(other) ⇒ Object
71
72
73
|
# File 'lib/fake_dynamo/key.rb', line 71
def <=>(other)
[primary, range] <=> [other.primary, other.range]
end
|
#[](name) ⇒ Object
38
39
40
41
42
|
# File 'lib/fake_dynamo/key.rb', line 38
def [](name)
return @primary if @primary.name == name
return @range if @range and @range.name == name
nil
end
|
#as_hash ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/fake_dynamo/key.rb', line 55
def as_hash
result = @primary.as_hash
if @range
result.merge!(@range.as_hash)
end
result
end
|
#as_key_hash ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/fake_dynamo/key.rb', line 63
def as_key_hash
result = { 'HashKeyElement' => { @primary.type => @primary.value }}
if @range
result.merge!({'RangeKeyElement' => { @range.type => @range.value }})
end
result
end
|
#eql?(key) ⇒ Boolean
44
45
46
47
48
49
|
# File 'lib/fake_dynamo/key.rb', line 44
def eql?(key)
return false unless key.kind_of? Key
@primary == key.primary &&
@range == key.range
end
|
#hash ⇒ Object
51
52
53
|
# File 'lib/fake_dynamo/key.rb', line 51
def hash
primary.hash ^ range.hash
end
|