tiny_dyno 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/lib/tiny_dyno/document.rb +1 -1
- data/lib/tiny_dyno/version.rb +1 -1
- metadata +2 -3
- data/lib/tiny_dyno/hash_keys.rb +0 -134
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f25a0b7a5a279763fa26f9086fb37804bb105e46
|
4
|
+
data.tar.gz: 0cd3addc209d7de1782c736aee2334a9070ef785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9206f02ceb2088dd6d95c8a7539adbbd0541f668ccf4b40f06097aff3238cdb95e265efa4755d224f9cb19f0efbe63784f5e3c869958c0ea8fa846d8fd4f6471
|
7
|
+
data.tar.gz: 595bb39ad21dbd37ac20e8e883320dfde768bb75443b889a0323a5dcbaa24f760a2c070a2cfab48093b0d23d1a265e5247287a103886823d7d802c7bb8562da6
|
data/CHANGES.md
CHANGED
data/lib/tiny_dyno/document.rb
CHANGED
@@ -59,7 +59,7 @@ module TinyDyno
|
|
59
59
|
get_query = build_where_query(options)
|
60
60
|
attributes = TinyDyno::Adapter.get_item(get_item_request: get_query)
|
61
61
|
if attributes.nil?
|
62
|
-
return
|
62
|
+
return nil
|
63
63
|
else
|
64
64
|
record = self.new(attributes)
|
65
65
|
record.instance_variable_set(:@new_record, false)
|
data/lib/tiny_dyno/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_dyno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Gerschner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -193,7 +193,6 @@ files:
|
|
193
193
|
- lib/tiny_dyno/fields/range_key.rb
|
194
194
|
- lib/tiny_dyno/fields/standard.rb
|
195
195
|
- lib/tiny_dyno/hash_key.rb
|
196
|
-
- lib/tiny_dyno/hash_keys.rb
|
197
196
|
- lib/tiny_dyno/loggable.rb
|
198
197
|
- lib/tiny_dyno/persistable.rb
|
199
198
|
- lib/tiny_dyno/stateful.rb
|
data/lib/tiny_dyno/hash_keys.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
module TinyDyno
|
2
|
-
module HashKeys
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
class_attribute :attribute_definitions, :key_schema, :hash_keys
|
7
|
-
|
8
|
-
# TODO :local_secondary_indexes, :global_secondary_indexes
|
9
|
-
self.attribute_definitions = []
|
10
|
-
self.key_schema = []
|
11
|
-
self.hash_keys = []
|
12
|
-
@hash_key_fields = []
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
# return all defined hash keys on an instantiated object
|
17
|
-
# for further use in DynamoDB queries
|
18
|
-
#
|
19
|
-
def hash_key_as_selector
|
20
|
-
selector = {}
|
21
|
-
self.class.hash_keys.each { |hk| selector[hk[:attr]] = attributes[hk[:attr]] }
|
22
|
-
selector
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
|
27
|
-
# Return true/false, depending on whether the provided argument
|
28
|
-
# matches a defined hash key for this document model
|
29
|
-
# @example Hash key is defined?
|
30
|
-
# Person.hash_key_is_defined?(:id)
|
31
|
-
#
|
32
|
-
# @param [ String ] name, the name of the hash key
|
33
|
-
# @return [ Boolean ] True, False
|
34
|
-
def hash_key_is_defined?(arg = nil)
|
35
|
-
@hash_key_fields.include?(arg)
|
36
|
-
end
|
37
|
-
|
38
|
-
# return the attribute_type as stored in the attribute_definitions
|
39
|
-
def lookup_attribute_type(attribute_name)
|
40
|
-
type = attribute_definitions.collect {|a| a[:attribute_type] if a[:attribute_name] == attribute_name }
|
41
|
-
type.first
|
42
|
-
end
|
43
|
-
|
44
|
-
# Defines all the fields that are accessible on the Document
|
45
|
-
# For each field that is defined, a getter and setter will be
|
46
|
-
# added as an instance method to the Document.
|
47
|
-
#
|
48
|
-
# @example Define a field.
|
49
|
-
# field :score, :type => Integer, :default => 0
|
50
|
-
#
|
51
|
-
# @param [ Symbol ] name The name of the field.
|
52
|
-
# @param [ Hash ] options The options to pass to the field.
|
53
|
-
#
|
54
|
-
# @option options [ Class ] :type The type of the field.
|
55
|
-
# @option options [ String ] :label The label for the field.
|
56
|
-
# @option options [ Object, Proc ] :default The field's default
|
57
|
-
#
|
58
|
-
# @return [ Field ] The generated field
|
59
|
-
def hash_key(name, options = {})
|
60
|
-
named = name.to_s
|
61
|
-
attribute_definition = build_attribute_definition(named,options[:type])
|
62
|
-
key_schema = build_key_schema(named)
|
63
|
-
unless attribute_definition_meets_spec?(attribute_definition)
|
64
|
-
raise TinyDyno::Errors::InvalidHashKey.new(klass: self.class, name: name)
|
65
|
-
end
|
66
|
-
# we need the accessors as well
|
67
|
-
add_field(named, options)
|
68
|
-
self.attribute_definitions << attribute_definition
|
69
|
-
self.key_schema << key_schema
|
70
|
-
# TODO
|
71
|
-
# should separate that out
|
72
|
-
self.hash_keys << {
|
73
|
-
attr: attribute_definition[:attribute_name],
|
74
|
-
attr_type: attribute_definition[:attribute_type],
|
75
|
-
key_type: key_schema[:key_type],
|
76
|
-
}
|
77
|
-
@hash_key_fields << attribute_definition[:attribute_name]
|
78
|
-
end
|
79
|
-
|
80
|
-
# convert a hash key into a format as expected by
|
81
|
-
# put_item and update_item request
|
82
|
-
def as_item_entry(hash_key)
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
# Return true or false, depending on whether the attribute_definitions on the model
|
89
|
-
# meet the specification of the Aws Sdk
|
90
|
-
# This is a syntax, not a logic check
|
91
|
-
def attribute_definitions_meet_spec?
|
92
|
-
attribute_definitions.each do |definition|
|
93
|
-
return false unless attribute_definition_meets_spec?(definition)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def attribute_definition_meets_spec?(definition)
|
98
|
-
return (definition.has_key?(:attribute_name) && \
|
99
|
-
definition.has_key?(:attribute_type) && \
|
100
|
-
definition[:attribute_name].class == String && \
|
101
|
-
definition[:attribute_type].class == String && \
|
102
|
-
['S','N', 'B'].include?(definition[:attribute_type]))
|
103
|
-
end
|
104
|
-
|
105
|
-
def build_attribute_definition(name, key_type)
|
106
|
-
{
|
107
|
-
attribute_name: name,
|
108
|
-
attribute_type: hash_key_type(key_type)
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def hash_key_type(key_type = nil)
|
113
|
-
return 'S' if key_type == String
|
114
|
-
return 'N' if key_type == Fixnum or key_type == Integer
|
115
|
-
return nil
|
116
|
-
end
|
117
|
-
|
118
|
-
def build_key_schema(name)
|
119
|
-
{
|
120
|
-
attribute_name: name,
|
121
|
-
key_type: 'HASH'
|
122
|
-
}
|
123
|
-
end
|
124
|
-
|
125
|
-
# convert values in queries to DynamoDB
|
126
|
-
# into types as expected by DynamoDB
|
127
|
-
def dyno_typed_key(key:, val:)
|
128
|
-
typed_class = self.fields[key].options[:type]
|
129
|
-
return (document_typed(klass: typed_class, value: val))
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|