business_process 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/business_process/base.rb +54 -17
- data/lib/business_process/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df59c8b6089724799b47fe7b79c4f2d88993bb5
|
4
|
+
data.tar.gz: 10f9abd12327ecdcc0fe2226b9edecdc6bac77cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4912e2e02886cc32b4594b3e25bd27840b16c3c4b106fb575a58c948779c0464bb7adaa171dd69fb9cf17ed8b24daeb67f3a9ad3a3ca1b90b4805b2a61d3269f
|
7
|
+
data.tar.gz: a2718b2f2aff9e2cc46c593bf952c32d400fdb62bd0c3df31c04221c3be19a0b0fc35e7e07a811c5fcd5b20aa4e381459fc14bda1a76ac249a877de93c258a83
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module BusinessProcess
|
2
2
|
class Base
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class_attribute :steps_queue, :requirements
|
4
|
+
attr_accessor :result
|
5
|
+
attr_reader :parameter_object, :error
|
6
|
+
private :result=, :parameter_object
|
6
7
|
|
7
|
-
def self.call(parameter_object
|
8
|
-
new(parameter_object
|
8
|
+
def self.call(parameter_object)
|
9
|
+
new(parameter_object).tap do |business_process|
|
9
10
|
business_process.instance_eval do
|
10
11
|
self.result = call
|
12
|
+
@success = !!self.result unless @success == false
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -27,28 +29,63 @@ module BusinessProcess
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
def initialize(parameter_object
|
32
|
+
def initialize(parameter_object)
|
31
33
|
@parameter_object = parameter_object
|
32
|
-
@options = options
|
33
34
|
end
|
34
35
|
|
35
|
-
attr_accessor :result
|
36
|
-
attr_reader :parameter_object, :options
|
37
|
-
private :result=, :parameter_object, :options
|
38
|
-
|
39
36
|
# Defaults to the boolean'ed result of "call"
|
40
37
|
def success?
|
41
|
-
|
38
|
+
@success
|
42
39
|
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def fail(error = nil)
|
42
|
+
@error = error
|
43
|
+
@success = false
|
44
|
+
raise error if error.is_a?(Class) && (error < Exception)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.steps(*step_names)
|
48
|
+
self.steps_queue = step_names
|
47
49
|
end
|
48
50
|
|
49
|
-
# Business process
|
50
51
|
def call
|
51
|
-
|
52
|
+
if steps.present?
|
53
|
+
process_steps
|
54
|
+
else
|
55
|
+
raise NoMethodError, "Called undefined #call. You need either define steps or implement the #call method in the class: #{self.class.name}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def process_steps
|
62
|
+
_result = nil
|
63
|
+
steps.map(&:to_s).each do |step_name|
|
64
|
+
_result = process_step(step_name)
|
65
|
+
return if @success == false
|
66
|
+
end
|
67
|
+
_result
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_step(step_name)
|
71
|
+
if respond_to?(step_name, true)
|
72
|
+
send(step_name)
|
73
|
+
else
|
74
|
+
begin
|
75
|
+
step_class = step_name.classify.constantize
|
76
|
+
step_class.call(self).result
|
77
|
+
rescue NameError => exc
|
78
|
+
if step_name.starts_with?('return_') and respond_to?(step_name.sub('return_', ''), true)
|
79
|
+
send(step_name.sub('return_', ''))
|
80
|
+
else
|
81
|
+
raise NoMethodError, "Cannot find step implementation for <#{step_name}>. Step should be either a private instance method of #{self.class.name} or camel_case'd name of another business process class.\n Original exception: #{exc.message}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def steps
|
88
|
+
self.class.steps_queue || []
|
52
89
|
end
|
53
90
|
end
|
54
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stevo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project: "[none]"
|
56
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.4.2
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: General purpose service object abstraction
|