steppy 0.8.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 0b128da90504e724d13b80d528e0b2a6ae30ca2e4c66e4cdd73469fd39ada2d7
4
- data.tar.gz: 0a0a54f5c5998e49b36dc72dfae5187e3a091d2196cb3480cb4b24208127c6c4
3
+ metadata.gz: 30867b1459b5e8f622fab73e25889a6fe09d208be7ffbf7cb5690ca084db7663
4
+ data.tar.gz: 7be40ff6c8e140c27249ab0722b90ddcab93ab5a01a12665f00ea6caddcd6293
5
5
  SHA512:
6
- metadata.gz: 3fff21268b6b4c85f470ff3bf15560a33431c76b4ef18cc587253d2a011e3d1934d6264ca064724aca96385f38081065b833ce6a2907f44a453aaf70e3c30b30
7
- data.tar.gz: 243916f06fcd329bd99ce81969a24d2ba38abe2da50c62d1f48f9d918b9862a75c474be08a851fb8f9825af1ea6ca731aa79c5829588aa3d4d41b3a230599ba7
6
+ metadata.gz: b081ebbfd0946d7a7ad50f98c52f81009cf26d8deeaf472ac41e2d96c36b8fc3bf98467d9be740bd8dac11389f512e77555e5450d6f45b3a3b2c713bba37d1e5
7
+ data.tar.gz: f7bd1e7b9fedd99b7067da79bb7c0303581bbc7623874f42ce5462a3cb8e25303abdf4f66a6c012053a88cd00670ed502e5f3fb403db6219ba8c93034245b5be
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ tags
9
10
  .*
10
11
  # allow these files/folders
11
12
  !.gitignore
@@ -1,3 +1,4 @@
1
+ ---
1
2
  inherit_from:
2
3
  - .rubocop_airbnb.yml
3
4
 
@@ -11,9 +12,6 @@ Style/FrozenStringLiteralComment:
11
12
  SupportedStyles:
12
13
  - always
13
14
 
14
- Style/StringLiterals:
15
- Enabled: true
16
-
17
15
  AllCops:
18
16
  TargetRubyVersion: 2.5
19
17
 
@@ -23,5 +21,14 @@ Airbnb/ClassOrModuleDeclaredInWrongFile:
23
21
  Airbnb/ModuleMethodInWrongFile:
24
22
  Enabled: false
25
23
 
24
+ Airbnb/OptArgParameters:
25
+ Enabled: false
26
+
26
27
  Lint/EndAlignment:
27
28
  EnforcedStyleAlignWith: variable
29
+
30
+ Style/StringLiterals:
31
+ EnforcedStyle: single_quotes
32
+ SupportedStyles:
33
+ - single_quotes
34
+ - double_quotes
@@ -1,2 +1,3 @@
1
+ ---
1
2
  require:
2
3
  - rubocop-airbnb
data/Gemfile CHANGED
@@ -7,4 +7,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in steppy.gemspec
8
8
  gemspec
9
9
 
10
- gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
10
+ gem 'byebug', platforms: %i(mri mingw x64_mingw)
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steppy (0.8.0)
4
+ steppy (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.0)
10
+ awesome_print (1.8.0)
10
11
  axiom-types (0.1.1)
11
12
  descendants_tracker (~> 0.0.4)
12
13
  ice_nine (~> 0.11.0)
@@ -14,6 +15,7 @@ GEM
14
15
  byebug (10.0.2)
15
16
  codeclimate-engine-rb (0.4.1)
16
17
  virtus (~> 1.0)
18
+ coderay (1.1.2)
17
19
  coercible (1.0.0)
18
20
  descendants_tracker (~> 0.0.1)
19
21
  descendants_tracker (0.0.4)
@@ -22,11 +24,15 @@ GEM
22
24
  equalizer (0.0.11)
23
25
  ice_nine (0.11.2)
24
26
  json (2.1.0)
27
+ method_source (0.9.2)
25
28
  minitest (5.11.3)
26
29
  parallel (1.12.1)
27
30
  parser (2.5.1.2)
28
31
  ast (~> 2.4.0)
29
32
  powerpack (0.1.2)
33
+ pry (0.12.2)
34
+ coderay (~> 1.1.0)
35
+ method_source (~> 0.9.0)
30
36
  rainbow (3.0.0)
31
37
  rake (10.5.0)
32
38
  reek (4.8.2)
@@ -51,6 +57,8 @@ GEM
51
57
  json (>= 1.8, < 3)
52
58
  simplecov-html (~> 0.10.0)
53
59
  simplecov-html (0.10.2)
60
+ super_awesome_print (0.2.5)
61
+ awesome_print
54
62
  thread_safe (0.3.6)
55
63
  unicode-display_width (1.4.0)
56
64
  virtus (1.0.5)
@@ -66,12 +74,14 @@ DEPENDENCIES
66
74
  bundler (~> 1.16)
67
75
  byebug
68
76
  minitest (~> 5.1)
77
+ pry
69
78
  rake (~> 10.0)
70
79
  reek (~> 4.8.1)
71
80
  rubocop (~> 0.52.1)
72
81
  rubocop-airbnb
73
82
  simplecov (~> 0.16.1)
74
83
  steppy!
84
+ super_awesome_print
75
85
 
76
86
  BUNDLED WITH
77
- 1.16.2
87
+ 1.17.2
data/Rakefile CHANGED
@@ -9,4 +9,4 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.test_files = FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
- task :default => :test
12
+ task default: :test
@@ -12,14 +12,10 @@ module Steppy
12
12
  end
13
13
 
14
14
  # :reek:TooManyStatements
15
- def self.parse_step(method:, args:, block:)
16
- if args.key?(:if)
17
- args[:condition] = args.delete(:if)
18
- end
15
+ def self.parse_step(method:, args:, block: nil)
16
+ args[:condition] = -> { steppy_run_condition(args[:if]) } if args.key?(:if)
19
17
 
20
- if args.key?(:unless)
21
- args[:condition] = -> { !steppy_run_condition(args.delete(:unless)) }
22
- end
18
+ args[:condition] = -> { !steppy_run_condition(args[:unless]) } if args.key?(:unless)
23
19
 
24
20
  args[:prefix] = :step unless args.key?(:prefix)
25
21
 
@@ -41,31 +37,84 @@ module Steppy
41
37
  steppy_cache[:sets] += sets
42
38
  end
43
39
 
44
- def step(method = nil, args = {}, &block) # rubocop:disable Airbnb/OptArgParameters
45
- steppy_cache[:steps].push(
46
- Steppy.parse_step({ method: method, args: args, block: block })
40
+ def step(method = nil, args = {}, &block)
41
+ steps.push(
42
+ Steppy.parse_step(method: method, args: args, block: block)
47
43
  )
48
44
  self
49
45
  end
46
+
50
47
  alias step_return step
51
48
 
52
49
  def step_if(condition, &block)
53
- steppy_cache[:steps].push(condition: condition, block: block)
50
+ steps.push(condition: condition, block: block)
54
51
  self
55
52
  end
56
53
 
57
54
  def step_unless(condition, &block)
58
- steppy_cache[:steps].push(condition: -> { !steppy_run_condition(condition) }, block: block)
55
+ steps.push(condition: -> { !steppy_run_condition(condition) }, block: block)
59
56
  self
60
57
  end
61
58
 
62
- def step_rescue(exceptions = nil, &block) # rubocop:disable Airbnb/OptArgParameters
59
+ def step_rescue(exceptions = nil, &block)
63
60
  steppy_cache[:rescues].push(exceptions: exceptions, block: block)
64
61
  self
65
62
  end
66
63
 
64
+ def step_if_else(condition_block, step_steps, args = {})
65
+ if_step, else_step = step_steps
66
+
67
+ steps.push Steppy.parse_step(
68
+ method: if_step,
69
+ args: {
70
+ if: condition_block,
71
+ }.merge(args)
72
+ )
73
+
74
+ steps.push Steppy.parse_step(
75
+ method: else_step,
76
+ args: {
77
+ unless: condition_block,
78
+ }.merge(args)
79
+ )
80
+ end
81
+
82
+ def step_after(key = nil, &block)
83
+ step_add_callback(:after, block, key)
84
+ end
85
+
86
+ def step_before(key = nil, &block)
87
+ step_add_callback(:before, block, key)
88
+ end
89
+
90
+ def step_add_callback(type, block, key)
91
+ callback_key = key ? key.to_sym : :global
92
+ callbacks = step_callbacks[type][callback_key] ||= []
93
+ callbacks.push(block)
94
+ end
95
+
96
+ def steps
97
+ steppy_cache[:steps]
98
+ end
99
+
100
+ def step_callbacks
101
+ steppy_cache[:callbacks]
102
+ end
103
+
67
104
  def steppy_cache
68
- @steppy_cache ||= SteppyCache.new(steps: [], sets: [], rescues: [])
105
+ @steppy_cache ||= SteppyCache.new(
106
+ steps: [],
107
+ sets: [],
108
+ rescues: [],
109
+ callbacks: {
110
+ before: {
111
+ global: [],
112
+ },
113
+ after: {
114
+ global: [],
115
+ },
116
+ }
117
+ )
69
118
  end
70
119
  end
71
120
 
@@ -73,7 +122,7 @@ module Steppy
73
122
  module InstanceMethods
74
123
  attr_reader :steppy_cache
75
124
 
76
- def steppy(attributes, cache = {})
125
+ def steppy(attributes = {}, cache = {})
77
126
  steppy_initialize_cache({ attributes: attributes, prefix: :step }.merge(cache))
78
127
 
79
128
  if steppy_cache.key?(:block)
@@ -81,7 +130,7 @@ module Steppy
81
130
  else
82
131
  steppy_run(steppy_cache)
83
132
  end
84
- rescue => exception
133
+ rescue StandardError => exception
85
134
  steppy_rescue exception, steppy_cache[:rescues]
86
135
  end
87
136
 
@@ -89,9 +138,10 @@ module Steppy
89
138
  steppy_sets(sets)
90
139
  end
91
140
 
92
- def step(method = nil, args = {}, &block) # rubocop:disable Airbnb/OptArgParameters
93
- steppy_run_step Steppy.parse_step({ method: method, args: args, block: block })
141
+ def step(method = nil, args = {}, &block)
142
+ steppy_run_step Steppy.parse_step(method: method, args: args, block: block)
94
143
  end
144
+
95
145
  alias step_return step
96
146
 
97
147
  def step_if(condition, &block)
@@ -137,10 +187,9 @@ module Steppy
137
187
 
138
188
  def steppy_rescue(exception, rescues)
139
189
  exception_class = exception.class
190
+ has_exception = exception_class == SteppyError || rescues.empty?
140
191
 
141
- if exception_class == SteppyError || rescues.empty?
142
- raise exception
143
- end
192
+ raise exception if has_exception
144
193
 
145
194
  rescues.each do |exceptions:, block:|
146
195
  if !exceptions || (exceptions && !exceptions.include?(exception_class))
@@ -152,9 +201,7 @@ module Steppy
152
201
  end
153
202
 
154
203
  def steppy_run_condition_block(condition, block)
155
- if steppy_run_condition(condition)
156
- steppy_run(steppy_cache_from_block(block))
157
- end
204
+ steppy_run(steppy_cache_from_block(block)) if steppy_run_condition(condition)
158
205
  end
159
206
 
160
207
  def steppy_run_condition(condition)
@@ -168,23 +215,34 @@ module Steppy
168
215
  end
169
216
 
170
217
  def steppy_run_step(method:, args:, block:)
171
- if !steppy_run_condition(args[:condition]) || (
172
- steppy_cache[:prefix] != args[:prefix]
173
- )
218
+ if !steppy_run_condition(args[:condition]) || (steppy_cache[:prefix] != args[:prefix])
174
219
  return steppy_result
175
220
  end
176
221
 
222
+ step_callbacks(:before, method, args, args)
223
+
177
224
  result = if block
178
225
  instance_exec(steppy_attributes, &block)
179
226
  else
180
227
  steppy_run_method(method, steppy_attributes)
181
228
  end
182
229
 
230
+ step_callbacks(:after, method, result, args)
231
+
183
232
  steppy_set(args[:set], result)
184
233
 
185
234
  result
186
235
  end
187
236
 
237
+ def step_callbacks(type, method, result, args)
238
+ callbacks = steppy_cache[:callbacks][type]
239
+ method_callbacks = (callbacks[method] || [])
240
+
241
+ callbacks[:global].concat(method_callbacks).each do |callback|
242
+ instance_exec(result, args, &callback)
243
+ end
244
+ end
245
+
188
246
  def steppy_run_method(method_name, attributes)
189
247
  method = "#{steppy_cache[:prefix]}_#{method_name}"
190
248
 
@@ -3,9 +3,8 @@
3
3
  # Incase you need to throw an error related to steppy
4
4
  class SteppyError < StandardError
5
5
  attr_reader :steppy
6
- # rubocop:disable Airbnb/OptArgParameters
6
+
7
7
  def initialize(steppy = nil)
8
- # rubocop:enable Airbnb/OptArgParameters
9
8
  if steppy
10
9
  @steppy = steppy
11
10
  message = steppy.is_a?(String) ? steppy : steppy.to_json
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Steppy
4
- VERSION = '0.8.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -5,28 +5,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'steppy/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'steppy'
9
- spec.version = Steppy::VERSION
10
- spec.authors = ['cj']
11
- spec.email = ['cjlazell@gmail.com']
8
+ spec.name = 'steppy'
9
+ spec.version = Steppy::VERSION
10
+ spec.authors = ['cj']
11
+ spec.email = ['cjlazell@gmail.com']
12
12
 
13
- spec.summary = %q()
14
- spec.description = %q()
15
- spec.homepage = 'https://github.com/cj/steppy'
16
- spec.license = 'MIT'
13
+ spec.summary = ''
14
+ spec.description = ''
15
+ spec.homepage = 'https://github.com/cj/steppy'
16
+ spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
19
  f.match(%r{^(test|spec|features)/})
20
20
  end
21
- spec.bindir = 'exe'
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.16'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
26
  spec.add_development_dependency 'minitest', '~> 5.1'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
28
29
  spec.add_development_dependency 'reek', '~> 4.8.1'
29
30
  spec.add_development_dependency 'rubocop', '~> 0.52.1'
30
31
  spec.add_development_dependency 'rubocop-airbnb'
31
32
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
33
+ spec.add_development_dependency 'super_awesome_print'
32
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steppy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-20 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,33 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '5.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '5.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '5.1'
61
+ version: '10.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '5.1'
68
+ version: '10.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: reek
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: 0.16.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: super_awesome_print
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: ''
112
140
  email:
113
141
  - cjlazell@gmail.com
@@ -153,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
181
  version: '0'
154
182
  requirements: []
155
183
  rubyforge_project:
156
- rubygems_version: 2.7.7
184
+ rubygems_version: 2.7.6.2
157
185
  signing_key:
158
186
  specification_version: 4
159
187
  summary: ''