appfuel 0.5.16 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/appfuel.rb +0 -6
- data/lib/appfuel/application.rb +1 -0
- data/lib/appfuel/application/app_container.rb +5 -1
- data/lib/appfuel/application/feature_helper.rb +28 -0
- data/lib/appfuel/feature/initializer.rb +6 -6
- data/lib/appfuel/handler/action.rb +16 -0
- data/lib/appfuel/handler/base.rb +7 -0
- data/lib/appfuel/handler/validator_dsl.rb +52 -44
- data/lib/appfuel/validation.rb +16 -0
- data/lib/appfuel/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3feb73535c4eb07de3fcca35f7b37ec547cec376
|
4
|
+
data.tar.gz: 5cc4db87f924c4f7f32f27a9def34dfd2d9181be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3f2383b9f7e3dd1596ff198b65a291e42cceaf8d5742906956ae6de0dcfcfeee6de5d5bbb9f275b0beff917ee5ab24997099f18eea6bd24fed04eeb4e597a79
|
7
|
+
data.tar.gz: 8277b5082e0717a1120437bb75925494941f7bcebfae0ea10123c92e4af404fd141abd57cc65eaf56c31ddd346cb1d5e76d331f4d4d4f9804b93ab98c7a4c706
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +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.6.0]](https://github.com/rsb/appfuel/releases/tag/0.6.0) 2017-08-10
|
9
|
+
### Added
|
10
|
+
- Validation to handlers
|
11
|
+
- Dispatching actions to other actions added to the handler
|
12
|
+
- New mixin `Application::FeatureHelper` to aid in feature initialization
|
13
|
+
|
8
14
|
## [[0.5.16]](https://github.com/rsb/appfuel/releases/tag/0.5.16) 2017-08-08
|
9
15
|
### Fixed
|
10
16
|
- response handler no longer has double error keys
|
data/lib/appfuel.rb
CHANGED
@@ -146,15 +146,10 @@ module Appfuel
|
|
146
146
|
|
147
147
|
exclude.map! {|item| item.to_s}
|
148
148
|
namespace = "#{key}.initializers"
|
149
|
-
finished_key = "#{key}.initialized"
|
150
149
|
runlist_key = "#{namespace}.run"
|
151
150
|
env = container['env']
|
152
151
|
config = container['config']
|
153
152
|
|
154
|
-
if container.key?(finished_key) && container[finished_key] == true
|
155
|
-
return false
|
156
|
-
end
|
157
|
-
|
158
153
|
runlist = []
|
159
154
|
if container.key?(runlist_key)
|
160
155
|
runlist = container[runlist_key]
|
@@ -181,7 +176,6 @@ module Appfuel
|
|
181
176
|
raise error
|
182
177
|
end
|
183
178
|
end
|
184
|
-
container.register(finished_key, true)
|
185
179
|
|
186
180
|
container
|
187
181
|
end
|
data/lib/appfuel/application.rb
CHANGED
@@ -7,6 +7,7 @@ module Appfuel
|
|
7
7
|
def self.included(base)
|
8
8
|
base.extend(ClassMethods)
|
9
9
|
base.extend(ContainerClassRegistration)
|
10
|
+
base.extend(FeatureHelper)
|
10
11
|
end
|
11
12
|
|
12
13
|
module ClassMethods
|
@@ -230,7 +231,6 @@ module Appfuel
|
|
230
231
|
def app_container
|
231
232
|
Appfuel.app_container(container_root_name)
|
232
233
|
end
|
233
|
-
|
234
234
|
end
|
235
235
|
|
236
236
|
# Instance methods
|
@@ -242,6 +242,10 @@ module Appfuel
|
|
242
242
|
self.class.app_container
|
243
243
|
end
|
244
244
|
|
245
|
+
def feature_name
|
246
|
+
self.class.feature_name
|
247
|
+
end
|
248
|
+
|
245
249
|
end
|
246
250
|
end
|
247
251
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Appfuel
|
2
|
+
module Application
|
3
|
+
module FeatureHelper
|
4
|
+
def feature_initialized?(key)
|
5
|
+
key = extract_feature_name(key)
|
6
|
+
flag_key = "#{key}.initialized"
|
7
|
+
container = Appfuel.app_container
|
8
|
+
return false unless container.key?(flag_key)
|
9
|
+
|
10
|
+
container[flag_key] == true
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize_feature(key)
|
14
|
+
key = extract_feature_name(key)
|
15
|
+
container = Appfuel.app_container
|
16
|
+
|
17
|
+
initializer = container[:feature_initializer]
|
18
|
+
initializer.call(key, container)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extract_feature_name(key)
|
22
|
+
return key unless key.include?('.')
|
23
|
+
parts = key.split('.')
|
24
|
+
parts[0] == 'features' ? parts[1] : parts[0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -14,7 +14,11 @@ module Appfuel
|
|
14
14
|
def call(name, container)
|
15
15
|
name = name.to_s.underscore
|
16
16
|
feature_key = "features.#{name}"
|
17
|
-
|
17
|
+
finished_key = "#{feature_key}.initialized"
|
18
|
+
|
19
|
+
if container.key?(finished_key) && container[finished_key] == true
|
20
|
+
return false
|
21
|
+
end
|
18
22
|
|
19
23
|
unless container.key?(feature_key)
|
20
24
|
Appfuel.setup_container_dependencies(feature_key, container)
|
@@ -39,6 +43,7 @@ module Appfuel
|
|
39
43
|
|
40
44
|
|
41
45
|
Appfuel.run_initializers(feature_key, container)
|
46
|
+
container.register(finished_key, true)
|
42
47
|
true
|
43
48
|
end
|
44
49
|
|
@@ -47,11 +52,6 @@ module Appfuel
|
|
47
52
|
disable_key = "#{feature_key}.disable_require"
|
48
53
|
container.key?(disable_key) && container[disable_key] == true
|
49
54
|
end
|
50
|
-
|
51
|
-
def initialized?(container, feature_key)
|
52
|
-
init_key = "#{feature_key}.initialized"
|
53
|
-
container.key?(init_key) && container[init_key] == true
|
54
|
-
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -15,6 +15,22 @@ module Appfuel
|
|
15
15
|
"actions.#{super}"
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def dispatch(route, payload = {})
|
20
|
+
route = route.to_s
|
21
|
+
fail "route can not be empty" if route.empty?
|
22
|
+
|
23
|
+
route = "#{feature_name}/#{route}" unless route.include?('/')
|
24
|
+
root = app_container[:root]
|
25
|
+
root.call(route, payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
def dispatch!(route, payload = {})
|
29
|
+
response = dispatch(route, payload)
|
30
|
+
fail_handler!(response) if response.failure?
|
31
|
+
|
32
|
+
response.ok
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
data/lib/appfuel/handler/base.rb
CHANGED
@@ -74,6 +74,7 @@ module Appfuel
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
# Instance methods
|
77
78
|
attr_reader :data
|
78
79
|
|
79
80
|
def initialize(container = Dry::Container.new)
|
@@ -117,6 +118,12 @@ module Appfuel
|
|
117
118
|
|
118
119
|
container[key].call(data, inputs)
|
119
120
|
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def fail_handler!(response)
|
125
|
+
self.class.fail_handler!(response)
|
126
|
+
end
|
120
127
|
end
|
121
128
|
end
|
122
129
|
end
|
@@ -68,12 +68,16 @@ module Appfuel
|
|
68
68
|
# call: run the lamda
|
69
69
|
module ValidatorDsl
|
70
70
|
|
71
|
+
def validator_keys
|
72
|
+
@validator_keys ||= []
|
73
|
+
end
|
74
|
+
|
71
75
|
def validators(*args)
|
72
76
|
@validators ||= []
|
73
77
|
return @validators if args.empty?
|
74
78
|
|
75
79
|
args.each do |arg|
|
76
|
-
|
80
|
+
validator_keys << convert_to_container_key(arg)
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
@@ -94,33 +98,18 @@ module Appfuel
|
|
94
98
|
# @return [Nil]
|
95
99
|
def validator(key = nil, opts = {}, &block)
|
96
100
|
key = default_validator_name if key.nil?
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
# load a validator with the given key from the app container.
|
102
|
-
#
|
103
|
-
# @note the key is encode and will be decoded first
|
104
|
-
# @see ValidatorDsl#convert_to_container_key for details
|
105
|
-
#
|
106
|
-
# @param key [String]
|
107
|
-
# @param opts [Hash]
|
108
|
-
# @return Appfuel::Validation::Validator
|
109
|
-
def load_validator(key, opts = {})
|
110
|
-
fail "validator must have a key" if key.nil?
|
111
|
-
|
112
|
-
container_key = convert_to_container_key(key)
|
113
|
-
container = Appfuel.app_container
|
114
|
-
unless container.key?(container_key)
|
115
|
-
fail "Could not locate validator with (#{container_key})"
|
101
|
+
unless block_given?
|
102
|
+
validator_keys << convert_to_container_key(key)
|
103
|
+
return
|
116
104
|
end
|
117
105
|
|
118
|
-
|
106
|
+
validators << Appfuel::Validation.build_validator(key, opts, &block)
|
107
|
+
nil
|
119
108
|
end
|
120
109
|
|
121
110
|
# return [Bool]
|
122
111
|
def validators?
|
123
|
-
!validators.empty?
|
112
|
+
!(validators.empty? && validator_keys.empty?)
|
124
113
|
end
|
125
114
|
|
126
115
|
# Used when resolving inputs to determine if we should apply any
|
@@ -139,6 +128,15 @@ module Appfuel
|
|
139
128
|
@skip_validation = true
|
140
129
|
end
|
141
130
|
|
131
|
+
def load_validators
|
132
|
+
list = validators
|
133
|
+
return list unless list.empty?
|
134
|
+
validator_keys.each do |key|
|
135
|
+
@validators << load_validator(key, no_context: true)
|
136
|
+
end
|
137
|
+
validators
|
138
|
+
end
|
139
|
+
|
142
140
|
# Validate all inputs using the list of validators that were assigned
|
143
141
|
# using the dsl methods.
|
144
142
|
#
|
@@ -150,7 +148,7 @@ module Appfuel
|
|
150
148
|
|
151
149
|
response = nil
|
152
150
|
has_failed = false
|
153
|
-
|
151
|
+
load_validators.each do |validator|
|
154
152
|
if validator.pipe?
|
155
153
|
result = handle_validator_pipe(validator, inputs)
|
156
154
|
inputs = result unless result == false
|
@@ -173,6 +171,23 @@ module Appfuel
|
|
173
171
|
response
|
174
172
|
end
|
175
173
|
|
174
|
+
def load_validator(key, opts = {})
|
175
|
+
unless opts[:no_context] == true
|
176
|
+
key = convert_to_container_key(key)
|
177
|
+
end
|
178
|
+
|
179
|
+
container = app_container
|
180
|
+
feature_name = extract_feature_name(key)
|
181
|
+
unless feature_initialized?(feature_name)
|
182
|
+
initialize_feature(feature_name)
|
183
|
+
end
|
184
|
+
|
185
|
+
unless container.key?(key)
|
186
|
+
fail "Could not locate validator with (#{key})"
|
187
|
+
end
|
188
|
+
container[key]
|
189
|
+
end
|
190
|
+
|
176
191
|
private
|
177
192
|
|
178
193
|
# Decodes the given key into a dependency injection namespace that is
|
@@ -182,35 +197,28 @@ module Appfuel
|
|
182
197
|
# @param key [String]
|
183
198
|
# #return [String]
|
184
199
|
def convert_to_container_key(key)
|
200
|
+
# normalize the key to the current feature when no feature
|
201
|
+
# is specified
|
202
|
+
unless key.include?('.')
|
203
|
+
key = "#{container_feature_name}.#{key}"
|
204
|
+
end
|
185
205
|
parts = key.to_s.split('.')
|
186
206
|
last = parts.last
|
187
207
|
first = parts.first
|
208
|
+
prefix = container_feature_key
|
209
|
+
if first != 'global' && first != container_feature_name
|
210
|
+
prefix = "#{container_features_root_name}.#{first}"
|
211
|
+
end
|
212
|
+
|
188
213
|
case first
|
189
|
-
when 'global'
|
190
|
-
|
191
|
-
when '
|
192
|
-
"global.validator-pipes.#{last}"
|
193
|
-
when 'pipe'
|
194
|
-
"#{container_feature_key}.validator-pipes.#{last}"
|
214
|
+
when 'global' then "global.validators.#{last}"
|
215
|
+
when 'global-pipe' then "global.validator-pipes.#{last}"
|
216
|
+
when 'pipe' then "#{prefix}.validator-pipes.#{last}"
|
195
217
|
else
|
196
|
-
"#{
|
218
|
+
"#{prefix}.validators.#{last}"
|
197
219
|
end
|
198
220
|
end
|
199
221
|
|
200
|
-
# Create a validator for the handler or load it from the container
|
201
|
-
# depending on if a block is given
|
202
|
-
#
|
203
|
-
# @param key [String] key used to identify the item
|
204
|
-
# @param opts [Hash]
|
205
|
-
# @return [
|
206
|
-
# Appfuel::Validation::Validator,
|
207
|
-
# Appfuel::Validation::ValidatorPipe
|
208
|
-
# ]
|
209
|
-
def build_validator(key, opts = {}, &block)
|
210
|
-
return load_validator(key, opts) unless block_given?
|
211
|
-
|
212
|
-
Appfuel::Validation.build_validator(key, opts, &block)
|
213
|
-
end
|
214
222
|
|
215
223
|
# Creates a response the first time otherwise it merges the results
|
216
224
|
# from the last validator into the response
|
data/lib/appfuel/validation.rb
CHANGED
@@ -3,7 +3,9 @@ require_relative 'validation/validator_pipe'
|
|
3
3
|
|
4
4
|
module Appfuel
|
5
5
|
module Validation
|
6
|
+
extend Appfuel::Application::FeatureHelper
|
6
7
|
class << self
|
8
|
+
|
7
9
|
# Dsl used create and register validators in the app container. The key
|
8
10
|
# needs to be the fully qualified feature or global.
|
9
11
|
#
|
@@ -30,6 +32,20 @@ module Appfuel
|
|
30
32
|
container.register(key, validator)
|
31
33
|
end
|
32
34
|
|
35
|
+
def load_schema(key)
|
36
|
+
feature = extract_feature_name(key)
|
37
|
+
container = Appfuel.app_container
|
38
|
+
key, _basename = build_validator_key(key)
|
39
|
+
unless feature_initialized?(feature)
|
40
|
+
initialize_feature(feature)
|
41
|
+
end
|
42
|
+
|
43
|
+
unless container.key?(key)
|
44
|
+
fail "Could not load validator key #{key}"
|
45
|
+
end
|
46
|
+
container[key]
|
47
|
+
end
|
48
|
+
|
33
49
|
# Turns the block of code given into a Dry::Validation schema or formi
|
34
50
|
# which is then used to create our validator.
|
35
51
|
#
|
data/lib/appfuel/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.1
|
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-08-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -288,6 +288,7 @@ files:
|
|
288
288
|
- lib/appfuel/application/app_container.rb
|
289
289
|
- lib/appfuel/application/container_class_registration.rb
|
290
290
|
- lib/appfuel/application/dispatcher.rb
|
291
|
+
- lib/appfuel/application/feature_helper.rb
|
291
292
|
- lib/appfuel/application/root.rb
|
292
293
|
- lib/appfuel/cli_msg_request.rb
|
293
294
|
- lib/appfuel/config.rb
|