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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42233ddf7c0eec955525558b26bbc00a77dbaa2d
4
- data.tar.gz: a59df790bfb781939132c7ef884efe08be31a31d
3
+ metadata.gz: 6df59c8b6089724799b47fe7b79c4f2d88993bb5
4
+ data.tar.gz: 10f9abd12327ecdcc0fe2226b9edecdc6bac77cc
5
5
  SHA512:
6
- metadata.gz: e43ea3f9984cd415b881bdb9a14082d5908ff9e5656f9f086954ccee1a567af2779a16c1d4ca1cf9a773ab56b775076eba03007a2bf5fe30c3040c978ea15d67
7
- data.tar.gz: 03774ef4933aeafede5b0b0f1958b4335018dddc55309b0180ab6560c930ab193c424a05f353ae0cf35cc0efa36451cc4a1e556249a176843da9e48390292ff2
6
+ metadata.gz: 4912e2e02886cc32b4594b3e25bd27840b16c3c4b106fb575a58c948779c0464bb7adaa171dd69fb9cf17ed8b24daeb67f3a9ad3a3ca1b90b4805b2a61d3269f
7
+ data.tar.gz: a2718b2f2aff9e2cc46c593bf952c32d400fdb62bd0c3df31c04221c3be19a0b0fc35e7e07a811c5fcd5b20aa4e381459fc14bda1a76ac249a877de93c258a83
@@ -1,13 +1,15 @@
1
1
  module BusinessProcess
2
2
  class Base
3
- class << self
4
- attr_accessor :requirements
5
- end
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, options={})
8
- new(parameter_object, options).tap do |business_process|
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, options = {})
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
- !!result
38
+ @success
42
39
  end
43
40
 
44
- # Checks if parameter object responds to all methods that process needs
45
- def valid?
46
- self.class.requirements.all? { |required_method| parameter_object.respond_to?(required_method) }
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
- raise NoMethodError, "Called undefined #call. You need to implement the method in the class: #{self.class.name}"
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
@@ -1,3 +1,3 @@
1
1
  module BusinessProcess
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.1"
3
3
  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: 0.0.1
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: 2014-06-29 00:00:00.000000000 Z
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.2.2
56
+ rubygems_version: 2.4.2
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: General purpose service object abstraction