appfuel 0.5.8 → 0.5.9

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: 5c8b9e19b1a6eb8dc07f3ddb296f5e4af70fe848
4
- data.tar.gz: 8b746ca541b5e33c99ee2d719452f1c84265718c
3
+ metadata.gz: 01694bfb7b1b82467a7416337c19a837a8eb47e4
4
+ data.tar.gz: 70eff28c04fa90216add52b3a443af8697c41404
5
5
  SHA512:
6
- metadata.gz: aac076ef608c55b1b55674c8ea37d9b576d037bad0404e1a888ddbb66b5e19e8bf6668c923a02e3a3fdc1a55369b67c5df3a5c70e32ec0ff86c27aa05e70339e
7
- data.tar.gz: 84e50e4263cec503206c0b5843e49b32c5484cc6314ea9878e28a2655969a74da387b34ef35035deff306267fb57b1842c5f6e22c61475d91c7439a3df62fa9d
6
+ metadata.gz: 5e88d8348a698285e0443f61b26a5bf2be05b689b63eb4d079b63416f0981bb04e9a473027a7baf1900b04837c6e1311a1298a4511de9efd8234402c897e4644
7
+ data.tar.gz: 7fab691e8d97d7a35c875b890869f9be117713faa63f66efe977cf3f28fa7febe6330bd6441a3708bf2f15f456f0247536a92117ccf120edf3dd053899d4bc4b
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ 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
9
+ ### Added
10
+ - Adding a `run!` to handler which deals with failures
11
+ - Adding a HandlerFailure has for when the handler fails
12
+ - New interfaces for the aws dynamo db adapter
13
+
14
+ ### Fixed
15
+ - Domain dsl attribute with array member and default is now working
16
+ - Updating dry-validations & dry-types
8
17
 
9
18
  ## [[0.5.8]](https://github.com/rsb/appfuel/releases/tag/0.5.8) 2017-07-20
10
19
  ### Fixed
data/appfuel.gemspec CHANGED
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  # or the way I am using it.
26
26
  spec.add_dependency "activerecord", "~> 5.1.1"
27
27
  spec.add_dependency "pg", "~> 0.20"
28
- spec.add_dependency "dry-types", "0.9.2"
28
+ spec.add_dependency "dry-types", "0.11"
29
29
  spec.add_dependency "dry-container", "~> 0.6"
30
- spec.add_dependency "dry-validation", "~> 0.10.5"
30
+ spec.add_dependency "dry-validation", "~> 0.11"
31
31
  spec.add_dependency "dry-monads", "~> 0.2"
32
32
  spec.add_dependency "dry-configurable", "~> 0.6"
33
33
  spec.add_dependency "parslet", "~> 1.8.0"
@@ -7,6 +7,8 @@ module Appfuel
7
7
  container[:feature_initializer].call(request.feature, container)
8
8
  action = container[:action_loader].call(request.namespace, container)
9
9
  response = action.run(request.inputs)
10
+ rescue Appfuel::Handler::HandlerFailure => e
11
+ response = e.response
10
12
  rescue => e
11
13
  handler = Appfuel::ResponseHandler.new
12
14
  response = handler.error(e)
@@ -85,11 +85,8 @@ module Appfuel
85
85
  def build_type(type_str, **options)
86
86
  base = type_str.split('.').last
87
87
  type = Types[type_str]
88
- type = apply_defaults(type, options)
89
88
  type = apply_optional(type, options)
90
-
91
89
  nil_is_allowed = allow_nil?(options)
92
-
93
90
  type = case base
94
91
  when 'hash' then handle_hash(type, options)
95
92
  when 'array' then handle_array(type, options)
@@ -97,6 +94,7 @@ module Appfuel
97
94
  type
98
95
  end
99
96
 
97
+ type = apply_defaults(type, options)
100
98
  type = apply_constraints(type, options)
101
99
 
102
100
  # You have to apply all the contraints before summing nil
@@ -208,23 +206,20 @@ module Appfuel
208
206
  end
209
207
 
210
208
  def handle_array(type, options)
211
- if options.key?(:member)
212
- member = options.delete(:member)
213
- member = member.is_a?(String) ? Types[member] : member
214
- type = type.member(member)
215
- end
216
- type
209
+ return type unless options.key?(:member)
210
+ member = options.delete(:member)
211
+ member = member.is_a?(String) ? Types[member] : member
212
+ type.member(member)
217
213
  end
218
214
 
219
215
  def apply_defaults(type, options)
220
216
  return type unless options.key?(:default)
221
-
222
- type.default(options.delete(:default))
217
+ default_value = options.delete(:default)
218
+ type.default(default_value)
223
219
  end
224
220
 
225
221
  def apply_optional(type, options)
226
222
  return type unless options.key?(:optional)
227
-
228
223
  options.delete(:optional)
229
224
  type.optional
230
225
  end
@@ -189,10 +189,9 @@ module Appfuel
189
189
  end
190
190
 
191
191
  def initialize_value(key, type, input)
192
- if input == Types::Undefined && type.default?
192
+ if (input == Types::Undefined || input == nil) && type.default?
193
193
  input = type[nil]
194
194
  end
195
-
196
195
  # manual overrides have to manually type check themselves
197
196
  setter = "#{key}="
198
197
  return send(setter, input) if respond_to?(setter)
@@ -41,6 +41,13 @@ module Appfuel
41
41
  result
42
42
  end
43
43
 
44
+ def run!(inputs = {}, container = Dry::Container.new)
45
+ result = run(inputs, container)
46
+ fail_handler!(result) if result.failure?
47
+
48
+ result.ok
49
+ end
50
+
44
51
  def error(*args)
45
52
  response_handler.error(*args)
46
53
  end
@@ -57,6 +64,14 @@ module Appfuel
57
64
  response_handler.create_response(data)
58
65
  end
59
66
 
67
+ def fail_handler!(response)
68
+ raise create_handler_failure(response)
69
+ end
70
+
71
+ def create_handler_failure(response)
72
+ title = "#{container_class_path} Failed:"
73
+ HandlerFailure.new(title, response)
74
+ end
60
75
  end
61
76
 
62
77
  attr_reader :data
@@ -5,17 +5,6 @@ module Appfuel
5
5
  def container_class_type
6
6
  'commands'
7
7
  end
8
-
9
- def resolve_dependencies(results = Dry::Container.new)
10
- =begin
11
- super
12
- resolve_container(results)
13
- resolve_domains(results)
14
- resolve_db_models(results)
15
- resolve_repos(results)
16
- results
17
- =end
18
- end
19
8
  end
20
9
  end
21
10
  end
@@ -0,0 +1,11 @@
1
+ module Appfuel
2
+ module Handler
3
+ class HandlerFailure < StandardError
4
+ attr_reader :response
5
+ def initialize(msg = "Unknown handler error", response)
6
+ @response = response
7
+ super(msg)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative 'handler/validator_dsl'
2
2
  require_relative 'handler/inject_dsl'
3
3
 
4
+ require_relative 'handler/handler_failure'
4
5
  require_relative 'handler/base'
5
6
  require_relative 'handler/action'
6
7
  require_relative 'handler/command'
@@ -1,4 +1,4 @@
1
1
  require_relative 'logging'
2
2
  require_relative 'db'
3
3
  require_relative 'web_api'
4
- require_relative 'aws_dynamodb'
4
+ require_relative 'dynamodb'
@@ -1,6 +1,6 @@
1
- Appfuel::Initialize.define('global.aws_dynamodb') do |config, container|
1
+ Appfuel::Initialize.define('global.dynamodb') do |config, container|
2
2
  require 'aws-sdk'
3
- require 'appfuel/storage/aws_dynamodb'
3
+ require 'appfuel/storage/dynamodb'
4
4
 
5
5
  env = config[:env]
6
6
  endpoint = config[:aws][:dynamodb][:endpoint]
@@ -14,5 +14,5 @@ Appfuel::Initialize.define('global.aws_dynamodb') do |config, container|
14
14
 
15
15
 
16
16
  client = Aws::DynamoDB::Client.new
17
- container.register(Appfuel::AwsDynamodb::CLIENT_CONTAINER_KEY, client)
17
+ container.register(Appfuel::Dynamodb::CLIENT_CONTAINER_KEY, client)
18
18
  end
@@ -0,0 +1,140 @@
1
+ module Appfuel
2
+ module Dynamodb
3
+ CLIENT_CONTAINER_KEY = 'aws.dynamodb.client'
4
+
5
+ class NoSqlModel
6
+ include Appfuel::Application::AppContainer
7
+
8
+ class << self
9
+ def container_class_type
10
+ 'dynamodb'
11
+ end
12
+
13
+ def config_key(value = nil)
14
+ return @config_key if value.nil?
15
+ @config_key = value.to_s
16
+ end
17
+
18
+ def load_config
19
+ config = app_container[:config]
20
+ key = config_key.to_s
21
+ if key.include?('.')
22
+ keys = key.split('.').map {|k| k.to_sym}
23
+ else
24
+ keys = [config_key]
25
+ end
26
+
27
+ @config ||= keys.each.inject(config) do |c, k|
28
+ unless c.key?(k)
29
+ fail "[dynamodb] config key (#{k}) not found - #{self}"
30
+ end
31
+ c[k]
32
+ end
33
+ end
34
+
35
+ def config
36
+ @config ||= load_config
37
+ end
38
+
39
+ def table_prefix
40
+ @table_prefex ||= config[:table_prefix]
41
+ end
42
+
43
+ def client
44
+ @client ||= app_container[CLIENT_CONTAINER_KEY]
45
+ end
46
+
47
+ def indexes
48
+ @indexes ||= {}
49
+ end
50
+
51
+ def table_name(value = nil)
52
+ return @table_name if value.nil?
53
+ @table_name = "#{table_prefix}#{value}"
54
+ end
55
+
56
+ def index(index_key, index_name)
57
+ indexes[index_key.to_sym] = "#{table_prefix}#{index_name}"
58
+ end
59
+
60
+ def inherited(klass)
61
+ stage_class_for_registration(klass)
62
+ end
63
+
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
70
+ end
71
+ end
72
+
73
+ # Instance methods
74
+
75
+ def client
76
+ self.class.client
77
+ end
78
+
79
+ def table_name
80
+ self.class.table_name
81
+ end
82
+
83
+ def table_prefix
84
+ self.class.table_prefix
85
+ end
86
+
87
+ def index_name(key)
88
+ unless self.class.indexes.key?(key)
89
+ fail "index #{key} has not been registered"
90
+ end
91
+ self.class.indexes[key]
92
+ end
93
+
94
+ def put_params(data)
95
+ {
96
+ table_name: table_name,
97
+ item: data
98
+ }
99
+ end
100
+
101
+ def table_params(keys ={})
102
+ {
103
+ table_name: table_name,
104
+ key: keys
105
+ }
106
+ end
107
+
108
+ def query_select_map(type)
109
+ case type
110
+ when :all_attrs then 'ALL_ATTRIBUTES'
111
+ when :all_projected then 'ALL_PROJECTED_ATTRIBUTES'
112
+ when :count then 'COUNT'
113
+ when :specific then 'SPECIFIC_ATTRIBUTES'
114
+ end
115
+ end
116
+
117
+ def select_index_params(key, attrs_returned, key_expr, values = {})
118
+ {
119
+ table_name: table_name,
120
+ index_name: index_name(key),
121
+ select: query_select_map(attrs_returned),
122
+ key_condition_expression: key_expr,
123
+ expression_attribute_values: values
124
+ }
125
+ end
126
+
127
+ def select_index(key, select, key_expr, values = {})
128
+ params = select_index_params(key, select, key_expr, values)
129
+ client.query(params)
130
+ end
131
+
132
+ def index_query_params(key, opts = {})
133
+ if opts.key?(:select)
134
+ params[:select] = query_select_map(opts[:select])
135
+ end
136
+
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,18 +1,23 @@
1
1
  module Appfuel
2
- module AwsDynamodb
2
+ module Dynamodb
3
3
  class Repository < Appfuel::Repository::Base
4
4
  class << self
5
5
  def container_class_type
6
- "#{super}.aws.dynamodb"
6
+ "#{super}.dynamodb"
7
7
  end
8
8
  end
9
9
 
10
10
  def storage_class(domain_name)
11
- mapper.storage_class('aws.dynamodb', domain_name)
11
+ mapper.storage_class('dynamodb', domain_name)
12
12
  end
13
13
 
14
14
  def to_entity(domain_name, storage)
15
- super(domain_name, 'aws.dynamodb', storage)
15
+ super(domain_name, 'dynamodb', storage)
16
+ end
17
+
18
+
19
+ def to_storage(domain, opts = {})
20
+ super(domain, 'dynamodb', opts)
16
21
  end
17
22
  end
18
23
  end
@@ -0,0 +1,2 @@
1
+ require_relative 'dynamodb/repository'
2
+ require_relative 'dynamodb/adapter'
@@ -191,8 +191,8 @@ module Appfuel
191
191
  mapper.exists?(expr)
192
192
  end
193
193
 
194
- def to_storage(entity, exclude = [])
195
- mapper.to_storage(entity, exclude)
194
+ def to_storage(entity, type, opts = {})
195
+ mapper.to_storage(entity, type, opts)
196
196
  end
197
197
 
198
198
  def to_entity(domain_name, type, storage)
@@ -1,3 +1,3 @@
1
1
  module Appfuel
2
- VERSION = "0.5.8"
2
+ VERSION = "0.5.9"
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.8
4
+ version: 0.5.9
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-21 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.9.2
47
+ version: '0.11'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.9.2
54
+ version: '0.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dry-container
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.10.5
75
+ version: '0.11'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.10.5
82
+ version: '0.11'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: dry-monads
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -311,13 +311,14 @@ files:
311
311
  - lib/appfuel/handler/action.rb
312
312
  - lib/appfuel/handler/base.rb
313
313
  - lib/appfuel/handler/command.rb
314
+ - lib/appfuel/handler/handler_failure.rb
314
315
  - lib/appfuel/handler/inject_dsl.rb
315
316
  - lib/appfuel/handler/validator_dsl.rb
316
317
  - lib/appfuel/initialize.rb
317
318
  - lib/appfuel/initialize/initializer.rb
318
319
  - lib/appfuel/initializers/all.rb
319
- - lib/appfuel/initializers/aws_dynamodb.rb
320
320
  - lib/appfuel/initializers/db.rb
321
+ - lib/appfuel/initializers/dynamodb.rb
321
322
  - lib/appfuel/initializers/logging.rb
322
323
  - lib/appfuel/initializers/web_api.rb
323
324
  - lib/appfuel/log_formatter.rb
@@ -331,9 +332,6 @@ files:
331
332
  - lib/appfuel/root_module.rb
332
333
  - lib/appfuel/run_error.rb
333
334
  - lib/appfuel/storage.rb
334
- - lib/appfuel/storage/aws_dynamodb.rb
335
- - lib/appfuel/storage/aws_dynamodb/no_sql_model.rb
336
- - lib/appfuel/storage/aws_dynamodb/repository.rb
337
335
  - lib/appfuel/storage/db.rb
338
336
  - lib/appfuel/storage/db/active_record_model.rb
339
337
  - lib/appfuel/storage/db/mapper.rb
@@ -342,6 +340,9 @@ files:
342
340
  - lib/appfuel/storage/db/migration_tasks.rb
343
341
  - lib/appfuel/storage/db/repository.rb
344
342
  - lib/appfuel/storage/db/repository_query.rb
343
+ - lib/appfuel/storage/dynamodb.rb
344
+ - lib/appfuel/storage/dynamodb/adapter.rb
345
+ - lib/appfuel/storage/dynamodb/repository.rb
345
346
  - lib/appfuel/storage/file.rb
346
347
  - lib/appfuel/storage/file/base.rb
347
348
  - lib/appfuel/storage/memory.rb
@@ -1,60 +0,0 @@
1
- module Appfuel
2
- module AwsDynamodb
3
- CLIENT_CONTAINER_KEY = 'aws.dynamodb.client'
4
- class NoSqlModel
5
- include Appfuel::Application::AppContainer
6
-
7
- class << self
8
- def container_class_type
9
- 'aws.dynamodb'
10
- end
11
-
12
- def config_key(value = nil)
13
- return @config_key if value.nil?
14
- @config_key = value.to_sym
15
- end
16
-
17
- def load_config
18
- config = app_container[:config]
19
- key = config_key.to_s
20
- if key.contains?('.')
21
- keys = config_key.split('.').map {|k| k.to_sym}
22
- else
23
- keys = [config_key]
24
- end
25
-
26
- keys.each.inject(config) do |c, k|
27
- unless c.key?(k)
28
- fail "[aws_dynamodb] config key (#{k}) not found - #{self}"
29
- end
30
- c[k]
31
- end
32
- end
33
-
34
- def load_client
35
- app_container[CLIENT_CONTAINER_KEY]
36
- end
37
-
38
- def table_name(value = nil)
39
- return @table_name if value.nil?
40
-
41
- prefix = load_config[:table_prefix]
42
- @table_name = "#{prefix}#{value}"
43
- end
44
-
45
- def inherited(klass)
46
- stage_class_for_registration(klass)
47
- end
48
- end
49
-
50
- attr_reader :config, :client
51
-
52
- def initialize
53
- @client = self.class.load_client
54
- @config = self.class.load_config
55
- @table_prefix = @config.fetch(:table_prefix) { '' }
56
- end
57
-
58
- end
59
- end
60
- end
@@ -1,2 +0,0 @@
1
- require_relative 'aws_dynamodb/repository'
2
- require_relative 'aws_dynamodb/no_sql_model'