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, key_schema_mismatch, param, validate!, validate_hash_condition, validate_hash_key, validate_index_names, validate_input, validate_key_data, validate_key_schema, validate_operation, validate_payload, validate_projection, validate_range_condition, validate_range_key, 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
|
#tertiary ⇒ Object
Returns the value of attribute tertiary.
6
7
8
|
# File 'lib/fake_dynamo/key.rb', line 6
def tertiary
@tertiary
end
|
Class Method Details
.create_attribute(key, data) ⇒ Object
53
54
55
56
57
|
# File 'lib/fake_dynamo/key.rb', line 53
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[key_schema.hash_key.name])
if key_schema.range_key
key.range = Attribute.from_hash(key_schema.range_key.name, key_data[key_schema.range_key.name])
end
key
end
|
.from_index_item(item, key_schema) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/fake_dynamo/key.rb', line 45
def from_index_item(item, key_schema)
key = Key.new
key.primary = item.key.primary
key.range = item[key_schema.range_key.name]
key.tertiary = item.key.range
key
end
|
.from_index_schema(data, index_schema, table_schema) ⇒ Object
local secondary indexes have a three part key: hash key -> primary index range key -> range table range key -> tertiary
35
36
37
38
39
40
41
42
43
|
# File 'lib/fake_dynamo/key.rb', line 35
def from_index_schema(data, index_schema, table_schema)
key = Key.new
validate_key_schema(data, index_schema)
validate_key_schema(data, table_schema)
key.primary = create_attribute(index_schema.hash_key, data)
key.range = create_attribute(index_schema.range_key, data)
key.tertiary = create_attribute(table_schema.range_key, data)
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
89
90
91
|
# File 'lib/fake_dynamo/key.rb', line 89
def <=>(other)
[primary, range, tertiary] <=> [other.primary, other.range, other.tertiary]
end
|
#[](name) ⇒ Object
60
61
62
63
64
|
# File 'lib/fake_dynamo/key.rb', line 60
def [](name)
return @primary if @primary.name == name
return @range if @range and @range.name == name
nil
end
|
#as_hash ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fake_dynamo/key.rb', line 78
def as_hash
result = @primary.as_hash
if @range
result.merge!(@range.as_hash)
end
if @tertiary
result.merge!(@tertiary.as_hash)
end
result
end
|
#eql?(key) ⇒ Boolean
66
67
68
69
70
71
72
|
# File 'lib/fake_dynamo/key.rb', line 66
def eql?(key)
return false unless key.kind_of? Key
@primary == key.primary &&
@range == key.range &&
@tertiary == key.tertiary
end
|
#hash ⇒ Object
74
75
76
|
# File 'lib/fake_dynamo/key.rb', line 74
def hash
primary.hash ^ range.hash ^ tertiary.hash
end
|