appfuel 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01694bfb7b1b82467a7416337c19a837a8eb47e4
4
- data.tar.gz: 70eff28c04fa90216add52b3a443af8697c41404
3
+ metadata.gz: 26008749776ba357f8a284a4feee76e7370c18c7
4
+ data.tar.gz: 0c2c61390c5e6e8a36a4b4101bd51ea49e97953f
5
5
  SHA512:
6
- metadata.gz: 5e88d8348a698285e0443f61b26a5bf2be05b689b63eb4d079b63416f0981bb04e9a473027a7baf1900b04837c6e1311a1298a4511de9efd8234402c897e4644
7
- data.tar.gz: 7fab691e8d97d7a35c875b890869f9be117713faa63f66efe977cf3f28fa7febe6330bd6441a3708bf2f15f456f0247536a92117ccf120edf3dd053899d4bc4b
6
+ metadata.gz: 47a10118db23f624497b4035fe3267239d3ebbde0da51fd98769033ce02656afe2859344c2037d57147047d7241e3193695a5ff30514a734bf39c2128da7129b
7
+ data.tar.gz: 5df321fb1f883bf3f7a6ed91d29517a515986933c9d8f5928d5dd81f4247c7e1b652951c6977b7c86e5403bb0109d34c288e1e2f4a53df7395e06e8104a6afde
data/CHANGELOG.md CHANGED
@@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file. (Pending ap
5
5
 
6
6
 
7
7
  # Releases
8
- ## [[0.5.9]](https://github.com/rsb/appfuel/releases/tag/0.5.8) 2017-07-27
8
+ ## [[0.5.10]](https://github.com/rsb/appfuel/releases/tag/0.5.10) 2017-07-28
9
+ ### Added
10
+ - Primary key object for dynamodb
11
+ - new adapter interfaces for get, put, and delete
12
+
13
+ ## [[0.5.9]](https://github.com/rsb/appfuel/releases/tag/0.5.9) 2017-07-27
9
14
  ### Added
10
15
  - Adding a `run!` to handler which deals with failures
11
16
  - Adding a HandlerFailure has for when the handler fails
@@ -1,2 +1,3 @@
1
- require_relative 'dynamodb/repository'
1
+ require_relative 'dynamodb/primary_key'
2
2
  require_relative 'dynamodb/adapter'
3
+ require_relative 'dynamodb/repository'
@@ -1,6 +1,7 @@
1
1
  module Appfuel
2
2
  module Dynamodb
3
- CLIENT_CONTAINER_KEY = 'aws.dynamodb.client'
3
+ DEFAULT_CONFIG_KEY = 'aws.dynamodb'
4
+ CLIENT_CONTAINER_KEY = "#{DEFAULT_CONFIG_KEY}.client"
4
5
 
5
6
  class NoSqlModel
6
7
  include Appfuel::Application::AppContainer
@@ -11,7 +12,9 @@ module Appfuel
11
12
  end
12
13
 
13
14
  def config_key(value = nil)
14
- return @config_key if value.nil?
15
+ if value.nil?
16
+ return @config_key ||= DEFAULT_CONFIG_KEY
17
+ end
15
18
  @config_key = value.to_s
16
19
  end
17
20
 
@@ -61,12 +64,8 @@ module Appfuel
61
64
  stage_class_for_registration(klass)
62
65
  end
63
66
 
64
- def primary_key(hash_key, hash_type, range_key = nil, range_type = nil)
65
- @primary_key = [ {hash_key => hash_type.to_s.downcase} ]
66
- unless range_key.nil?
67
- fail "range type is required" if range_type.nil?
68
- @primary_key << { range_key => range_type }
69
- end
67
+ def primary_key(hash, hash_type, range = nil, range_type = nil)
68
+ @primary_key = PrimaryKey.new(hash, hash_type, range, range_type)
70
69
  end
71
70
  end
72
71
 
@@ -91,18 +90,19 @@ module Appfuel
91
90
  self.class.indexes[key]
92
91
  end
93
92
 
93
+ def primary_key
94
+ fail "No primary key assigned" if self.class.primary_key.nil?
95
+ self.class.primary_key
96
+ end
97
+
98
+
94
99
  def put_params(data)
95
- {
96
- table_name: table_name,
97
- item: data
98
- }
100
+ create_table_hash(item: data)
99
101
  end
100
102
 
101
- def table_params(keys ={})
102
- {
103
- table_name: table_name,
104
- key: keys
105
- }
103
+ def table_params(hash_key_value, range_key_value = nil)
104
+ params = primary_key.params(hash_key_value, range_key_value)
105
+ create_table_hash(key: params)
106
106
  end
107
107
 
108
108
  def query_select_map(type)
@@ -115,13 +115,12 @@ module Appfuel
115
115
  end
116
116
 
117
117
  def select_index_params(key, attrs_returned, key_expr, values = {})
118
- {
119
- table_name: table_name,
118
+ create_table_hash(
120
119
  index_name: index_name(key),
121
- select: query_select_map(attrs_returned),
120
+ select: query_select_map(attrs_returned),
122
121
  key_condition_expression: key_expr,
123
122
  expression_attribute_values: values
124
- }
123
+ )
125
124
  end
126
125
 
127
126
  def select_index(key, select, key_expr, values = {})
@@ -129,11 +128,36 @@ module Appfuel
129
128
  client.query(params)
130
129
  end
131
130
 
132
- def index_query_params(key, opts = {})
133
- if opts.key?(:select)
134
- params[:select] = query_select_map(opts[:select])
135
- end
131
+ def put(data)
132
+ params = put_params(data)
133
+ ap params
134
+ client.put_item(params)
135
+ end
136
+
137
+ def get(hash_value, range_value = nil)
138
+ result = get_item(hash_value, range_value)
139
+ return false if result.item.nil?
140
+
141
+ result.item
142
+ end
143
+
144
+ def get_item(hash_value, range_value = nil)
145
+ params = table_params(hash_value, range_value)
146
+ client.get_item(params)
147
+ end
148
+
149
+ def delete(hash_value, range_value = nil)
150
+ delete_item(hash_value, range_value)
151
+ end
152
+
153
+ def delete_item(hash_value, range_value = nil)
154
+ params = table_params(hash_value, range_value)
155
+ client.delete_item(params)
156
+ end
136
157
 
158
+ private
159
+ def create_table_hash(data = {})
160
+ data.merge!(table_name: table_name)
137
161
  end
138
162
  end
139
163
  end
@@ -0,0 +1,34 @@
1
+ module Appfuel
2
+ module Dynamodb
3
+ class PrimaryKey
4
+ attr_reader :hash_key, :range_key
5
+
6
+ def initialize(hash_key, hash_type, range_key = nil, range_type = nil)
7
+ @hash_key = hash_key.to_sym
8
+ @hash_type = hash_type
9
+ unless range_key.nil?
10
+ if range_type.nil?
11
+ fail "range_type is required for primary range key"
12
+ end
13
+ @range_key = range_key
14
+ @range_type = range_type
15
+ end
16
+ end
17
+
18
+ def composite?
19
+ !range_key.nil?
20
+ end
21
+
22
+ def params(hash_value, range_value = nil)
23
+ data = { hash_key => hash_value }
24
+ if composite?
25
+ if range_value.nil?
26
+ fail "This is a composite key range_value is required"
27
+ end
28
+ data[range_key] = range_value
29
+ end
30
+ data
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ require 'securerandom'
2
+
1
3
  module Appfuel
2
4
  module Repository
3
5
  # The generic repository behavior. This represents repo behavior that is
@@ -237,6 +239,10 @@ module Appfuel
237
239
  app_container[key].new(hash)
238
240
  end
239
241
 
242
+ def generate_uuid
243
+ SecureRandom.uuid
244
+ end
245
+
240
246
  private
241
247
  def method_not_implemented_error
242
248
  fail "must be implemented by a storage specific repository"
@@ -1,3 +1,3 @@
1
1
  module Appfuel
2
- VERSION = "0.5.9"
2
+ VERSION = "0.5.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appfuel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Scott-Buccleuch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -342,6 +342,7 @@ files:
342
342
  - lib/appfuel/storage/db/repository_query.rb
343
343
  - lib/appfuel/storage/dynamodb.rb
344
344
  - lib/appfuel/storage/dynamodb/adapter.rb
345
+ - lib/appfuel/storage/dynamodb/primary_key.rb
345
346
  - lib/appfuel/storage/dynamodb/repository.rb
346
347
  - lib/appfuel/storage/file.rb
347
348
  - lib/appfuel/storage/file/base.rb