steppy 0.1.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e5453b4c6d2b926fbb62e294acf91d2a6620628d638120a4891211a425e3573
4
- data.tar.gz: 9d49834c0e7767236fe25f4ae37f9ad1c48ac04d7c4a8a430b5b9b3a91f1354e
3
+ metadata.gz: b5c0018ed2b1fb27c1825a10881930b947c258e5f6d0f456d2c060488da6ce30
4
+ data.tar.gz: 1e3ce8842b65d6043f46913bdb947a95f0293b6f12e782245ae0a19085e7fda6
5
5
  SHA512:
6
- metadata.gz: 86ce9ff1d59ca081127c6beb3ca7e065d0f2dc973ba97bbfae3f1f0704f6e5cee490e48d4035a63f460aed5f8a77e22ed589a67c4420b9957ee52c233cac64e4
7
- data.tar.gz: 984959949968858249dea683dc5ef6218b099503ec00b1dcbddf47885f89585db18f125b0bc53e70897633637036357487084d38bb7cd6c69ac44bf3bcf68fbf
6
+ metadata.gz: ab6c8040e0623533702d77bd1d560373bc0e965c5fc20250f00c5bed709482b17ae4dc962d191b9b1774b2318be2c9bc8bc7eb8f6d2cf8f44d27445404da0de4
7
+ data.tar.gz: cf04255913350e155ef2929d8c352d16692488e6dc1734ca34848ba73b63a8bbcd39a09d3b3b678b30edad5e684d64040caad5e96d91a688e4cd803b98ed43c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steppy (0.1.0)
4
+ steppy (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -74,4 +74,4 @@ DEPENDENCIES
74
74
  steppy!
75
75
 
76
76
  BUNDLED WITH
77
- 1.16.1
77
+ 1.16.2
data/lib/steppy.rb CHANGED
@@ -13,8 +13,8 @@ module Steppy
13
13
  # Steppy class methods that will be added to your included classes.
14
14
  module ClassMethods
15
15
  if !defined? step
16
- def step(method, **args)
17
- steppy_add step_method: method, step_args: args
16
+ def step(method, **args, &block)
17
+ steppy_add step_method: method, step_args: args, step_block: block
18
18
  end
19
19
  end
20
20
 
@@ -50,7 +50,8 @@ module Steppy
50
50
 
51
51
  # Steppy instance methods that will be added.
52
52
  module InstanceMethods
53
- def steppy(attributes)
53
+ def steppy(attributes, prefix: :step)
54
+ @steppy_prefix = prefix
54
55
  @steppy = { attributes: attributes.freeze }
55
56
 
56
57
  steppy_run(
@@ -94,18 +95,34 @@ module Steppy
94
95
  end
95
96
  end
96
97
 
97
- def steppy_step(step_method:, step_args:)
98
- method_name = "step_#{step_method}"
98
+ def steppy_step(step_method:, step_args:, step_block:)
99
+ method_name = "#{@steppy_prefix}_#{step_method}"
99
100
 
100
101
  steppy_if(step_args[:if]) && return
101
102
 
103
+ result = if step_block
104
+ steppy_run_block(step_block, steppy_attributes)
105
+ else
106
+ steppy_run_method(method_name, steppy_attributes)
107
+ end
108
+
109
+ steppy_set(step_args[:set], result)
110
+ end
111
+
112
+ def steppy_run_method(method_name, steppy_attributes)
102
113
  if method(method_name).arity > 0
103
- result = public_send(method_name, steppy_attributes)
114
+ public_send(method_name, steppy_attributes)
104
115
  else
105
- result = public_send(method_name)
116
+ public_send(method_name)
106
117
  end
118
+ end
107
119
 
108
- steppy_set(step_args[:set], result)
120
+ def steppy_run_block(step_block, steppy_attributes)
121
+ if step_block.arity > 0
122
+ instance_exec(steppy_attributes, &step_block)
123
+ else
124
+ instance_exec(&step_block)
125
+ end
109
126
  end
110
127
 
111
128
  def steppy_if(step_if)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Steppy
4
- VERSION = '0.1.0'
4
+ VERSION = '0.5.0'
5
5
  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.1.0
4
+ version: 0.5.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-05-28 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler