minidynamo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b06b99d8d9966437af6839720b1dab5d9de57dbc
4
+ data.tar.gz: 6108350ec6d417410f125db2ba8cf9733c24f7ab
5
+ SHA512:
6
+ metadata.gz: 61c1fc642c72e4249617dbdb922d856fda64ce31d39c6d304f186c7f893a54d5d26ccd3c5aeb861f0d03dc1c17e2f330bd57aa7299434364954eda47c2273eb8
7
+ data.tar.gz: 33993078342a9bfc9632121ab4484a670a1966217af25145fc8f9ab0ccc6a9f84faefcfbbbc7700d89a968a8615c78a1fd7f7d867d310ae3cbd5d5398d02c94c
data/Gemfile CHANGED
@@ -1,12 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "aws-sdk", ">= 1.11.3"
3
+ gem "aws-sdk", "~> 1.2.0"
4
4
 
5
5
  # Add dependencies to develop your gem here.
6
6
  # Include everything needed to run rake, tests, features, etc.
7
7
  group :development do
8
- gem "shoulda", ">= 0"
9
- gem "rdoc", "~> 3.12"
10
- gem "jeweler", "~> 1.8.4"
11
- #gem "simplecov", "~> 0.7.1"
8
+ #gem "shoulda", ">= 0"
9
+ #gem "rdoc", ">= 0"
10
+ gem "jeweler", "~> 1.8.7"
12
11
  end
data/Gemfile.lock CHANGED
@@ -1,39 +1,57 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.2.13)
5
- i18n (= 0.6.1)
6
- multi_json (~> 1.0)
7
- aws-sdk (1.11.3)
4
+ addressable (2.3.5)
5
+ aws-sdk (1.15.0)
8
6
  json (~> 1.4)
9
7
  nokogiri (< 1.6.0)
10
8
  uuidtools (~> 2.1)
11
- git (1.2.5)
12
- i18n (0.6.1)
13
- jeweler (1.8.4)
9
+ builder (3.2.2)
10
+ faraday (0.8.8)
11
+ multipart-post (~> 1.2.0)
12
+ git (1.2.6)
13
+ github_api (0.10.1)
14
+ addressable
15
+ faraday (~> 0.8.1)
16
+ hashie (>= 1.2)
17
+ multi_json (~> 1.4)
18
+ nokogiri (~> 1.5.2)
19
+ oauth2
20
+ hashie (2.0.5)
21
+ highline (1.6.19)
22
+ httpauth (0.2.0)
23
+ jeweler (1.8.7)
24
+ builder
14
25
  bundler (~> 1.0)
15
26
  git (>= 1.2.5)
27
+ github_api (= 0.10.1)
28
+ highline (>= 1.6.15)
29
+ nokogiri (= 1.5.10)
16
30
  rake
17
31
  rdoc
18
32
  json (1.8.0)
19
- multi_json (1.7.6)
33
+ jwt (0.1.8)
34
+ multi_json (>= 1.5)
35
+ multi_json (1.7.9)
36
+ multi_xml (0.5.5)
37
+ multipart-post (1.2.0)
20
38
  nokogiri (1.5.10)
21
- rake (10.0.4)
22
- rdoc (3.12.2)
39
+ oauth2 (0.9.2)
40
+ faraday (~> 0.8)
41
+ httpauth (~> 0.2)
42
+ jwt (~> 0.1.4)
43
+ multi_json (~> 1.0)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.5.2)
47
+ rake (10.1.0)
48
+ rdoc (4.0.1)
23
49
  json (~> 1.4)
24
- shoulda (3.5.0)
25
- shoulda-context (~> 1.0, >= 1.0.1)
26
- shoulda-matchers (>= 1.4.1, < 3.0)
27
- shoulda-context (1.1.2)
28
- shoulda-matchers (2.2.0)
29
- activesupport (>= 3.0.0)
30
50
  uuidtools (2.1.4)
31
51
 
32
52
  PLATFORMS
33
53
  ruby
34
54
 
35
55
  DEPENDENCIES
36
- aws-sdk (>= 1.11.3)
37
- jeweler (~> 1.8.4)
38
- rdoc (~> 3.12)
39
- shoulda
56
+ aws-sdk (~> 1.15.0)
57
+ jeweler (~> 1.8.7)
data/README.md CHANGED
@@ -81,3 +81,9 @@ You could go and create the table by calling `TestModel.create_table`
81
81
  * Commit and push until you are happy with your contribution.
82
82
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
83
83
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so we can cherry-pick around it.
84
+
85
+
86
+ NOTES
87
+ ====
88
+
89
+ * only number, binary or string are accepted on the table command types
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -13,13 +13,13 @@ module Minidynamo
13
13
  # inside the model
14
14
  def create_table
15
15
  create_opts = {}
16
- create_opts[:hash_key] = hash_key
17
- create_opts[:range_key] = range_key if range_key
16
+ create_opts[:hash_key] = convert_key_to_dynamo_db_types hash_key
17
+ create_opts[:range_key] = convert_key_to_dynamo_db_types range_key if range_key
18
18
 
19
- dynamo_db.tables.create dynamo_db_table_name,
20
- read_capacity,
21
- write_capacity,
22
- create_opts
19
+ dynamo_db.tables.create dynamo_db_table_name,
20
+ read_capacity,
21
+ write_capacity,
22
+ create_opts
23
23
  end
24
24
 
25
25
  # @return [DynamoDB::Table]
@@ -27,8 +27,8 @@ module Minidynamo
27
27
  # @api private
28
28
  def dynamo_db_table shard_name = nil
29
29
  table = dynamo_db.tables[dynamo_db_table_name(shard_name)]
30
- table.hash_key = hash_key #[:id, :string]
31
- table.range_key = range_key if range_key
30
+ table.hash_key = convert_key_to_dynamo_db_types(hash_key) #[:id, :string]
31
+ table.range_key = convert_key_to_dynamo_db_types(range_key) if range_key
32
32
 
33
33
  #table.hash_key = {:public_token => :string }
34
34
  #table.range_key = {:created_at => :string }
@@ -38,6 +38,27 @@ module Minidynamo
38
38
  table
39
39
  end
40
40
 
41
+ def convert_key_to_dynamo_db_types key
42
+ keyname = key.keys[0]
43
+ type = key[keyname]
44
+ equivalent_type = nil
45
+ case type
46
+ when :float
47
+ equivalent_type = :number
48
+ when :integer
49
+ equivalent_type = :number
50
+ when :boolean
51
+ equivalent_type = :number
52
+ when :binary
53
+ equivalent_type = :binary
54
+ else
55
+ equivalent_type = :string
56
+ end
57
+ key = {}
58
+ key[keyname] = equivalent_type
59
+ return key
60
+ end
61
+
41
62
 
42
63
  end
43
64
 
@@ -8,7 +8,7 @@ module Minidynamo
8
8
 
9
9
  data = table.items[id].attributes.to_h
10
10
 
11
- raise RecordNotFound, "no data found for id: #{id}" if data.empty?
11
+ raise AWS::Record::RecordNotFound, "no data found for id: #{id}" if data.empty?
12
12
 
13
13
  obj = self.new(:shard => table)
14
14
  obj.send(:hydrate, id, data)
@@ -22,7 +22,7 @@ module Minidynamo
22
22
  end
23
23
  type = key[hk]
24
24
  attribute_creator_method_name = "#{type.to_s}_attr".to_sym
25
- puts "hk: CALLING #{attribute_creator_method_name} with #{hk}"
25
+ #puts "hk: CALLING #{attribute_creator_method_name} with #{hk}"
26
26
  send attribute_creator_method_name, hk
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ module Minidynamo
31
31
  rk = key.keys[0]
32
32
  type = key[rk]
33
33
  attribute_creator_method_name = "#{type.to_s}_attr".to_sym
34
- puts "rk: CALLING #{attribute_creator_method_name} with #{rk}"
34
+ #puts "rk: CALLING #{attribute_creator_method_name} with #{rk}"
35
35
  send attribute_creator_method_name, rk
36
36
  end
37
37
 
data/minidynamo.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "minidynamo"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Pelaez"]
@@ -31,9 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/minidynamo/model/dynamo_db_overloads.rb",
32
32
  "lib/minidynamo/model/finder_overloads.rb",
33
33
  "lib/minidynamo/model/keys.rb",
34
- "minidynamo-0.1.0.gem",
35
34
  "minidynamo.gemspec",
36
- "model2.rb",
37
35
  "test/helper.rb",
38
36
  "test/test_minidynamo.rb"
39
37
  ]
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minidynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Pelaez
@@ -14,39 +13,34 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: aws-sdk
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.11.3
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.11.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: shoulda
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rdoc
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: jeweler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -99,37 +90,32 @@ files:
99
90
  - lib/minidynamo/model/dynamo_db_overloads.rb
100
91
  - lib/minidynamo/model/finder_overloads.rb
101
92
  - lib/minidynamo/model/keys.rb
102
- - minidynamo-0.1.0.gem
103
93
  - minidynamo.gemspec
104
- - model2.rb
105
94
  - test/helper.rb
106
95
  - test/test_minidynamo.rb
107
96
  homepage: http://github.com/vlipco/minidynamo
108
97
  licenses:
109
98
  - MIT
99
+ metadata: {}
110
100
  post_install_message:
111
101
  rdoc_options: []
112
102
  require_paths:
113
103
  - lib
114
104
  required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
105
  requirements:
117
- - - ! '>='
106
+ - - '>='
118
107
  - !ruby/object:Gem::Version
119
108
  version: '0'
120
- segments:
121
- - 0
122
- hash: 1782624063131978072
123
109
  required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
110
  requirements:
126
- - - ! '>='
111
+ - - '>='
127
112
  - !ruby/object:Gem::Version
128
113
  version: '0'
129
114
  requirements: []
130
115
  rubyforge_project:
131
- rubygems_version: 1.8.23
116
+ rubygems_version: 2.1.9
132
117
  signing_key:
133
118
  specification_version: 3
134
119
  summary: AWS SDK HashModel extension to support DynamoDB tables with hash-range keys
135
120
  test_files: []
121
+ has_rdoc:
data/minidynamo-0.1.0.gem DELETED
Binary file
data/model2.rb DELETED
@@ -1,199 +0,0 @@
1
- require 'aws-sdk'
2
-
3
- def precede_with_check(x)
4
- check_digit = CheckDigit.calculate_check_digit(x)
5
- "#{check_digit}#{x}"
6
- end
7
-
8
-
9
- module Minidynamo
10
-
11
-
12
- # Wrap some HashModel behaviour and offers minor overrides for readability
13
- # and to create tables using ranges.
14
- class Model < AWS::Record::HashModel
15
-
16
- class << self
17
-
18
- # For all the fields with defaults
19
- attr_writer :write_capacity, :read_capacity
20
-
21
- attr_accessor :range_key
22
-
23
- # Use the client table creator instead of the HashModel inheritance
24
- def create_table
25
- # TODO verify it's not already created
26
-
27
- create_opts = {}
28
- create_opts[:hash_key] = hash_key
29
- create_opts[:range_key] = range_key if range_key
30
-
31
-
32
- dynamo_db.tables.create dynamo_db_table_name,
33
- read_capacity,
34
- write_capacity,
35
- create_opts
36
-
37
- end
38
-
39
- # Obtain the DynamoDB status of a table
40
- def status
41
- end
42
-
43
- def count_total
44
-
45
- initial_q = dynamo_db.client.scan :table_name => dynamo_db_table_name,
46
- :count => true
47
- count = initial_q["Count"]
48
- if initial_q["LastEvaluatedKey"]
49
- last = initial_q["LastEvaluatedKey"]
50
- begin
51
- q = dynamo_db.client.scan :table_name => dynamo_db_table_name,
52
- :count => true,
53
- :exclusive_start_key => last
54
- count += q["Count"]
55
- last = q["LastEvaluatedKey"]
56
- end while last
57
- end
58
- count
59
-
60
- end
61
-
62
- def ddb_client
63
- @client ||= AWS::DynamoDB.new.client
64
- end
65
-
66
-
67
-
68
- #
69
- # TABLE THROUGHPUT HELPERS
70
- #
71
-
72
- def initial_througput options = {}
73
- self.read_capacity = options[:read_capacity]
74
- self.write_capacity = options[:write_capacity]
75
- end
76
-
77
- def read_capacity
78
- @read_capacity || 10
79
- end
80
-
81
- def write_capacity
82
- @write_capacity || 10
83
- end
84
-
85
- def hash_key
86
- @hash_key || {:id => :string}
87
- end
88
-
89
- def table options = {}
90
- set_shard_name options[:name]
91
- self.hash_key = options[:hash_key] unless options[:hash_key].nil?
92
- self.range_key = options[:range_key] unless options[:range_key].nil?
93
- end
94
-
95
- #
96
- # TABLE STRUCTURE HELPERS
97
- #
98
-
99
- def field key, type, options = {}
100
- method_name = "#{type.to_s}_attr".to_sym
101
- puts "CALLING #{method_name}"
102
- send method_name, key, options
103
- end
104
-
105
- def hash_key=(key)
106
- @hash_key = key
107
- hk = key.keys[0]
108
- finder_method_name = "find_by_#{hk}".to_sym
109
- self.define_singleton_method finder_method_name do |x|
110
- find_by_id x
111
- end
112
- type = key[hk]
113
- attribute_creator_method_name = "#{type.to_s}_attr".to_sym
114
- puts "CREATING HASH KEY ATTR #{attribute_creator_method_name}"
115
- send attribute_creator_method_name, hk
116
- end
117
-
118
- # OVERLOAD THE FINDER TO USE CUSTOM HASK KEYS IN ERRORS
119
-
120
- alias_method :_find_by_id, :find_by_id
121
- alias_method :_find, :find
122
-
123
- #data = table.items[id].attributes.to_h
124
- #
125
- #raise RecordNotFound, "no data found for id: #{id}" if data.empty?
126
- #
127
- #obj = self.new(:shard => table)
128
- #obj.send(:hydrate, id, data)
129
- #obj
130
- #
131
- #.query :table_name => "sample-table", :consistent_read => true, :hash_key_value => {:s => "123"}
132
-
133
- def find *args
134
- # If find(id), determine wether a query or regular find will work
135
- # convert the first argument to integer, if it's a string it'll yield 0
136
-
137
- # if the first argument is an integer and this is a table with range as main key
138
- if args.length == 1 && !args[0].is_a?(Symbol) && hash_range_table?
139
- items = rangeless_query args[0]
140
- case items.length
141
- when 0
142
- raise AWS::Record::RecordNotFound, "no data found for #{hash_key.keys[0]}: #{args[0]}"
143
- when 1
144
- return items[0]
145
- else
146
- return items
147
- end
148
- end
149
-
150
- #in any other case fall back to the default HashModel
151
- new_scope.find(*args)
152
- end
153
-
154
- # converts string > s, numeric > n
155
- def hash_key_type
156
- dynamo_db_table.hash_key.type.to_s.chars.first.to_sym
157
- end
158
-
159
- def rangeless_query(*args)
160
- # Map to string if that's the case. For any other type of hash_key
161
- # you will have to provide the converted value or errors might appear
162
- hash_key_type == :s ? hkv = args[0].to_s : hkv = args[0]
163
- result = dynamo_db.client.query :table_name => dynamo_db_table_name,
164
- :consistent_read => true,
165
- :hash_key_value => {hash_key_type => hkv}
166
-
167
- # Convert the result to items
168
- hashed_items = result["Items"]
169
- items = []
170
- hashed_items.each do |i|
171
- i_data = {}
172
- i.each do |k,v|
173
- # Obtain the first key for the hash describing the value of a DDB column
174
- k_data_type = i[k].keys[0]
175
- i_data[k] = i[k][k_data_type]
176
- end
177
- pt = PublicToken.new
178
- pt.send :hydrate, i_data["id"], i_data
179
- items << pt
180
- end
181
- items
182
- end
183
-
184
- def hash_range_table?
185
- ! hash_key.nil?
186
- end
187
-
188
- def find_by_id *args
189
- begin
190
- hash_range_table? ? rangeless_query(args) : _find_by_id(args)
191
-
192
- rescue AWS::Record::RecordNotFound
193
- raise AWS::Record::RecordNotFound, "no data found for #{hash_key}: #{id}"
194
- end
195
- end
196
-
197
- end
198
- end
199
- end