incredible 0.0.1.pre → 0.0.2.pre

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: 136f74de4f0fb1f2ce9b7c034536e309a3cec7ae
4
- data.tar.gz: 8144f9c6ace33e5a6b2442b8f7704ee0dbfb4a78
3
+ metadata.gz: 2719e5df6c532eb211e72a2ca189e31a7ccf7b8e
4
+ data.tar.gz: 1dead0a9b1eeeb8683e42fc97a8c81bf73e1277f
5
5
  SHA512:
6
- metadata.gz: 856c927d05693349103b26fc1754e85415d58ba4f52e858d93f2c244a1c609e73fd4ac5a8e27af9ea0ac2a8f1587552db81f6fbde061bc2a566c115b592f58e2
7
- data.tar.gz: 948ab2aeb444d19082b18cfc432a30e4b76e217d1d2961802d45431ab489f20cb524eb34770f7b18dff20ab63fb284b0bd404f832cacce4eab1adec302abcd17
6
+ metadata.gz: 49ea21f4e8fb664430e3431f88dd760fffef0d0e1a79cf9c04cfabfe78df2a38319e2eb8e37e4b6b80b6093ceccc202093b3083d3fcec22286827b5a38c1de16
7
+ data.tar.gz: f7e187f3cee82ee529b8af163b476728900127e1d378793c406368b338dd27023fc730e7d7aa33bbc9045c5a3a0cb1cde17a8736a8640b0f8b8790434d28b681
@@ -9,7 +9,7 @@ module Incredible
9
9
  end
10
10
 
11
11
  def steps
12
- @steps ||= raw_steps.map { |k, v| { k => Step.new(v) } }.reduce(:merge)
12
+ @steps ||= raw_steps.map { |k, v| { k => Step.new(k, v) } }.reduce(:merge)
13
13
  end
14
14
 
15
15
  def find_step(step_name)
@@ -1,15 +1,23 @@
1
1
  module Incredible
2
2
  class Step
3
-
4
- def initialize(data)
3
+
4
+ def initialize(name, data)
5
+ @name = name.to_s
5
6
  @data = data.symbolize_keys
6
7
 
7
- %I[questions rules template].each do |k|
8
+ %I[questions template].each do |k|
8
9
  self.class.send :define_method, k.to_sym do
9
10
  @data[k]
10
11
  end
11
12
  end
12
13
  end
13
14
 
15
+ def rule
16
+ rule_class = "#{@name.classify}Rule"
17
+ rule_class.constantize
18
+ rescue NameError
19
+ nil
20
+ end
21
+
14
22
  end
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module Incredible
2
- VERSION = '0.0.1.pre'.freeze
2
+ VERSION = '0.0.2.pre'.freeze
3
3
  end
@@ -21,11 +21,9 @@ module Incredible
21
21
  end
22
22
 
23
23
  def process_rules
24
- self.rules = step_data.rules || {}
25
- next_step = permitted_params.to_h.map do |k, v|
26
- rules.dig(k, v)
27
- end&.first
28
- jump_to next_step if next_step
24
+ return unless step_data.rule
25
+ next_step = step_data.rule.send(:process, permitted_params)
26
+ jump_to next_step
29
27
  end
30
28
 
31
29
  module ClassMethods
@@ -0,0 +1,8 @@
1
+ class Step1Rule
2
+
3
+ def self.process(params)
4
+ return unless params[:name] == 'Mike'
5
+ :step3
6
+ end
7
+
8
+ end
data/spec/step_spec.rb CHANGED
@@ -10,17 +10,11 @@ describe Incredible::Step do
10
10
  widget: 'text'
11
11
  }
12
12
  ],
13
- rules: {
14
- name: {
15
- 'Someone' => :next_step,
16
- 'Someone else' => :last_step
17
- }
18
- },
19
13
  template: 'my_template'
20
14
  }
21
15
  end
22
16
 
23
- let(:subject) { Incredible::Step.new(hash) }
17
+ let(:subject) { Incredible::Step.new('rule', hash) }
24
18
 
25
19
  context '#questions' do
26
20
 
@@ -37,15 +31,30 @@ describe Incredible::Step do
37
31
 
38
32
  end
39
33
 
40
- context '#rules' do
34
+ context '#rule' do
41
35
 
42
- it 'returns the rules' do
43
- expect(subject.rules).to eq(
44
- name: {
45
- 'Someone' => :next_step,
46
- 'Someone else' => :last_step
47
- }
48
- )
36
+ context 'when a rule is not present' do
37
+
38
+ before do
39
+ Object.send(:remove_const, :RuleRule) if defined?(RuleRule)
40
+ end
41
+
42
+ it 'returns nil' do
43
+ expect(subject.rule).to eq(nil)
44
+ end
45
+
46
+ end
47
+
48
+ context 'when a rule is present' do
49
+
50
+ before do
51
+ Object.const_set('RuleRule', Class.new)
52
+ end
53
+
54
+ it 'returns the rule' do
55
+ expect(subject.rule).to eq(RuleRule)
56
+ end
57
+
49
58
  end
50
59
 
51
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incredible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - pezholio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -160,6 +160,7 @@ files:
160
160
  - spec/dummy/app/controllers/forms_controller.rb
161
161
  - spec/dummy/app/models/application_record.rb
162
162
  - spec/dummy/app/models/stub_model.rb
163
+ - spec/dummy/app/rules/step1_rule.rb
163
164
  - spec/dummy/app/views/forms/bar.html.erb
164
165
  - spec/dummy/app/views/forms/foo.html.erb
165
166
  - spec/dummy/app/views/layouts/application.html.erb
@@ -224,48 +225,49 @@ signing_key:
224
225
  specification_version: 4
225
226
  summary: Build multi-page forms like a General
226
227
  test_files:
227
- - spec/dummy/package.json
228
+ - spec/spec_helper.rb
229
+ - spec/form_spec.rb
230
+ - spec/controllers/forms_controller_spec.rb
231
+ - spec/loader_spec.rb
228
232
  - spec/dummy/Rakefile
229
- - spec/dummy/config/spring.rb
233
+ - spec/dummy/config.ru
234
+ - spec/dummy/config/forms/bad-yaml.yml
235
+ - spec/dummy/config/forms/form.yml
230
236
  - spec/dummy/config/application.rb
231
- - spec/dummy/config/routes.rb
232
- - spec/dummy/config/boot.rb
237
+ - spec/dummy/config/environment.rb
233
238
  - spec/dummy/config/puma.rb
239
+ - spec/dummy/config/cable.yml
240
+ - spec/dummy/config/spring.rb
234
241
  - spec/dummy/config/environments/production.rb
235
242
  - spec/dummy/config/environments/test.rb
236
243
  - spec/dummy/config/environments/development.rb
237
- - spec/dummy/config/initializers/assets.rb
238
- - spec/dummy/config/initializers/inflections.rb
244
+ - spec/dummy/config/boot.rb
245
+ - spec/dummy/config/locales/en.yml
246
+ - spec/dummy/config/initializers/wrap_parameters.rb
239
247
  - spec/dummy/config/initializers/mime_types.rb
240
- - spec/dummy/config/initializers/filter_parameter_logging.rb
241
- - spec/dummy/config/initializers/backtrace_silencers.rb
248
+ - spec/dummy/config/initializers/inflections.rb
249
+ - spec/dummy/config/initializers/assets.rb
242
250
  - spec/dummy/config/initializers/cookies_serializer.rb
243
- - spec/dummy/config/initializers/wrap_parameters.rb
251
+ - spec/dummy/config/initializers/backtrace_silencers.rb
252
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
244
253
  - spec/dummy/config/initializers/application_controller_renderer.rb
245
- - spec/dummy/config/cable.yml
246
- - spec/dummy/config/environment.rb
247
254
  - spec/dummy/config/secrets.yml
248
- - spec/dummy/config/forms/form.yml
249
- - spec/dummy/config/forms/bad-yaml.yml
250
- - spec/dummy/config/locales/en.yml
251
- - spec/dummy/config.ru
252
- - spec/dummy/app/models/application_record.rb
253
- - spec/dummy/app/models/stub_model.rb
254
- - spec/dummy/app/controllers/forms_controller.rb
255
- - spec/dummy/app/controllers/application_controller.rb
256
- - spec/dummy/app/views/layouts/mailer.html.erb
257
- - spec/dummy/app/views/layouts/application.html.erb
258
- - spec/dummy/app/views/layouts/mailer.text.erb
259
- - spec/dummy/app/views/forms/bar.html.erb
260
- - spec/dummy/app/views/forms/foo.html.erb
255
+ - spec/dummy/config/routes.rb
256
+ - spec/dummy/bin/yarn
261
257
  - spec/dummy/bin/rake
262
258
  - spec/dummy/bin/bundle
263
259
  - spec/dummy/bin/rails
264
- - spec/dummy/bin/setup
265
- - spec/dummy/bin/yarn
266
260
  - spec/dummy/bin/update
267
- - spec/spec_helper.rb
268
- - spec/loader_spec.rb
269
- - spec/form_spec.rb
270
- - spec/controllers/forms_controller_spec.rb
261
+ - spec/dummy/bin/setup
262
+ - spec/dummy/app/rules/step1_rule.rb
263
+ - spec/dummy/app/views/forms/bar.html.erb
264
+ - spec/dummy/app/views/forms/foo.html.erb
265
+ - spec/dummy/app/views/layouts/application.html.erb
266
+ - spec/dummy/app/views/layouts/mailer.html.erb
267
+ - spec/dummy/app/views/layouts/mailer.text.erb
268
+ - spec/dummy/app/models/application_record.rb
269
+ - spec/dummy/app/models/stub_model.rb
270
+ - spec/dummy/app/controllers/forms_controller.rb
271
+ - spec/dummy/app/controllers/application_controller.rb
272
+ - spec/dummy/package.json
271
273
  - spec/step_spec.rb