appfuel 0.5.16 → 0.6.1

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: 331cd1aa71078ef100073a648bfac5eca51d638b
4
- data.tar.gz: cde5c43a46185a1dd993ad96cb6bfa87a5be679d
3
+ metadata.gz: 3feb73535c4eb07de3fcca35f7b37ec547cec376
4
+ data.tar.gz: 5cc4db87f924c4f7f32f27a9def34dfd2d9181be
5
5
  SHA512:
6
- metadata.gz: b0ae1714c7b54995a642ca34781797670f58967a6be934751a013e9665668a2c02817a9f81e95fe16011a5059be4ddbd6aae01117089b7136030cac23486485e
7
- data.tar.gz: 72aca40e39055e98494a73b3c439840595f6dd6a8082bc21e90d55d45162e705f930407b5d6c9f4cdeb18a3566eaa90f8bfa49e04958dda875e4e15355519175
6
+ metadata.gz: d3f2383b9f7e3dd1596ff198b65a291e42cceaf8d5742906956ae6de0dcfcfeee6de5d5bbb9f275b0beff917ee5ab24997099f18eea6bd24fed04eeb4e597a79
7
+ data.tar.gz: 8277b5082e0717a1120437bb75925494941f7bcebfae0ea10123c92e4af404fd141abd57cc65eaf56c31ddd346cb1d5e76d331f4d4d4f9804b93ab98c7a4c706
@@ -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
@@ -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
@@ -1,4 +1,5 @@
1
1
  require_relative 'application/dispatcher'
2
+ require_relative 'application/feature_helper'
2
3
  require_relative 'application/app_container'
3
4
  require_relative 'application/root'
4
5
  require_relative 'application/container_class_registration'
@@ -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
- return false if initialized?(container, feature_key)
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
@@ -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
- @validators << load_validator(arg)
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
- validators << build_validator(key, opts, &block)
98
- nil
99
- end
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
- container[container_key]
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
- validators.each do |validator|
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
- "global.validators.#{last}"
191
- when 'global-pipe'
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
- "#{container_feature_key}.validators.#{first}"
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
@@ -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
  #
@@ -1,3 +1,3 @@
1
1
  module Appfuel
2
- VERSION = "0.5.16"
2
+ VERSION = "0.6.1"
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.16
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-08 00:00:00.000000000 Z
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