business_flow 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/business_flow/base.rb +1 -5
- data/lib/business_flow/callable.rb +14 -1
- data/lib/business_flow/dsl.rb +36 -2
- data/lib/business_flow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b485a68eacf74616f5f9e0fe635e210e017c9249
|
4
|
+
data.tar.gz: a3f786a40733abc5299058190545226953178450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f74896456557f2042328b355973aabbe77b311466f76470fff9483a6d13a732c4847da248848bc61d4609115be75ff3eed27927e0c717ddaee58de7784fdaf25
|
7
|
+
data.tar.gz: 327b5cda58ad5add151556a4ad164ec360f0a0421f66827f4ba431f8bc21b075131f92aabc113b4ff491c80029357c9188b01e9c194801a7c543beadfdfb9990
|
data/Gemfile.lock
CHANGED
data/lib/business_flow/base.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
# Magic!
|
2
1
|
module BusinessFlow
|
3
|
-
#
|
4
|
-
# call! to raise errors
|
5
|
-
# Hooks for cross cutting concerns
|
6
|
-
# Figure out how much we can freeze
|
2
|
+
# include BusinessFlow::Base in any object to get a flow!
|
7
3
|
# :reek:ModuleInitialize
|
8
4
|
module Base
|
9
5
|
def self.included(klass)
|
@@ -24,7 +24,7 @@ module BusinessFlow
|
|
24
24
|
if @callable.is_a?(Proc)
|
25
25
|
@cached_proc = proc_callable
|
26
26
|
elsif @callable.respond_to?(:call)
|
27
|
-
@cached_proc =
|
27
|
+
@cached_proc = call_callable
|
28
28
|
elsif !@callable.is_a?(Symbol)
|
29
29
|
raise ArgumentError, 'callable must be a symbol or respond to #call'
|
30
30
|
end
|
@@ -52,6 +52,19 @@ module BusinessFlow
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def call_callable
|
56
|
+
proc do |instance, inputs|
|
57
|
+
case @callable.method(:call).arity
|
58
|
+
when 1, -1
|
59
|
+
@callable.call(inputs)
|
60
|
+
when 0
|
61
|
+
@callable.call
|
62
|
+
else
|
63
|
+
@callable.call(instance, inputs)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
55
68
|
def lookup_callable
|
56
69
|
constant_name = @callable.to_s.camelcase
|
57
70
|
@metaclass.parents.each do |parent|
|
data/lib/business_flow/dsl.rb
CHANGED
@@ -88,6 +88,33 @@ module BusinessFlow
|
|
88
88
|
# Keep our internal helpers in a different module to avoid polluting the
|
89
89
|
# namespace of whoever includes us.
|
90
90
|
module PrivateHelpers
|
91
|
+
# Handle some logic around conditions
|
92
|
+
class ConditionList
|
93
|
+
def initialize(if_stmts, unless_stmts, klass)
|
94
|
+
@klass = klass
|
95
|
+
@conditions = Array.wrap(if_stmts).map(&method(:to_if)) +
|
96
|
+
Array.wrap(unless_stmts).map(&method(:to_unless))
|
97
|
+
end
|
98
|
+
|
99
|
+
def call(instance, inputs)
|
100
|
+
@conditions.all? { |cond| cond.call(instance, inputs) }
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def to_if(cond)
|
106
|
+
Callable.new(cond, @klass)
|
107
|
+
end
|
108
|
+
|
109
|
+
def to_unless(cond)
|
110
|
+
if_stmt = to_if(cond)
|
111
|
+
unless_stmt = proc do |instance, input|
|
112
|
+
!if_stmt.call(instance, input)
|
113
|
+
end
|
114
|
+
to_if(unless_stmt)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
91
118
|
def self.create_parameter_field(klass, field)
|
92
119
|
klass.send(:define_method, field) do
|
93
120
|
if parameter_object.is_a?(Hash) && parameter_object.key?(field)
|
@@ -96,11 +123,18 @@ module BusinessFlow
|
|
96
123
|
parameter_object.public_send(field)
|
97
124
|
end
|
98
125
|
end
|
126
|
+
klass.send(:private, field)
|
99
127
|
end
|
100
128
|
|
101
129
|
def self.create_conditional_callable(klass, opts)
|
102
|
-
|
103
|
-
|
130
|
+
return unless opts[:if] || opts[:unless]
|
131
|
+
Callable.new(condition(klass, opts), klass)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.condition(klass, opts)
|
135
|
+
if_stmts = opts.fetch(:if, proc { true })
|
136
|
+
unless_stmts = opts.fetch(:unless, proc { false })
|
137
|
+
ConditionList.new(if_stmts, unless_stmts, klass)
|
104
138
|
end
|
105
139
|
|
106
140
|
def self.create_field(klass, field)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Scarborough
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|