business_flow 0.5.1 → 0.5.2

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: b6d31c1153f385fb6581857f81324b432890ad95
4
- data.tar.gz: 73c6b7c4e893e13815fac24b440a792057f37844
3
+ metadata.gz: 20dd5eb0ff89e49ebf99e3a47ec7383e8db07320
4
+ data.tar.gz: 23f9387a1ba8bea2d3d8d9afee4384bf002e0876
5
5
  SHA512:
6
- metadata.gz: 0619c1dc22b3e755b0cb65a385e0fc2388d242692ce41a9b9ac15b2672ce5ab276967ed4d4f609bbf88cd944f76793e0d0809bca88a1b41f79dfa1c959c969a4
7
- data.tar.gz: a73dd14cced41702e1f092761b55ee4af23920498dd2762b7d660b518447c8c3d9940346621ac9c2498277a05c3a445c202cdee5f248d0d88b239fdffd705a7e
6
+ metadata.gz: 23423eeb84a68119631859eaef316e9d18532c1c65d58ff3ee2cfb480026ff01e076d8f393a98395870df67252b4f998819d74322275ad5eb3abfa46afae3fd8
7
+ data.tar.gz: da02de0322b75a90946504689243862f4595e2a0adb7bff77919af7c309dd69723acebd5a0717d53729a123ad254f6087b47a526f140fe96bdb46f16b2b454e4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business_flow (0.5.1)
4
+ business_flow (0.5.2)
5
5
  activemodel (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
 
data/lib/business_flow.rb CHANGED
@@ -2,6 +2,7 @@ require 'active_model'
2
2
  require 'active_support/core_ext'
3
3
  require 'business_flow/version'
4
4
  require 'business_flow/not_nil_validator'
5
+ require 'business_flow/flow_failed_exception'
5
6
  require 'business_flow/callable'
6
7
  require 'business_flow/step'
7
8
  require 'business_flow/default_step_executor'
@@ -6,7 +6,8 @@ module BusinessFlow
6
6
  end
7
7
 
8
8
  def cache_key
9
- "#{self.class.name}/#{self.class.cache_key.call(self, nil)}"
9
+ klass = self.class
10
+ "#{klass.name}/#{klass.cache_key.call(self, nil)}"
10
11
  end
11
12
 
12
13
  # DSL Methods
@@ -35,22 +36,32 @@ module BusinessFlow
35
36
  end
36
37
  end
37
38
 
38
- # TODO: Make this some kind of private helper
39
- def cache_options
39
+ def call(*args)
40
+ flow = new(*args)
41
+ PrivateHelpers.execute(self, flow)
42
+ rescue FlowFailedException
43
+ flow
44
+ end
45
+ end
46
+
47
+ # Avoid polluting the namespace of whoever includes us
48
+ module PrivateHelpers
49
+ def self.execute(klass, flow)
50
+ klass.cache_store.fetch(flow.cache_key, cache_options(klass)) do
51
+ flow.call
52
+ raise FlowFailedException, flow if flow.errors.any?
53
+ flow
54
+ end
55
+ end
56
+
57
+ def self.cache_options(klass)
40
58
  # compact is not available in Ruby <2.4 or ActiveSupport < 4, so
41
59
  # we can't use it here.
42
60
  options = {}
43
- ttl = cache_ttl
61
+ ttl = klass.cache_ttl
44
62
  options[:expires_in] = ttl if ttl
45
63
  options
46
64
  end
47
-
48
- def call(*args)
49
- ret = new(*args)
50
- cache_store.fetch(ret.cache_key, cache_options) do
51
- ret.tap(&:call)
52
- end
53
- end
54
65
  end
55
66
  end
56
67
  end
@@ -60,6 +60,12 @@ module BusinessFlow
60
60
  new(parameter_object).tap(&:call)
61
61
  end
62
62
 
63
+ def call!(*args)
64
+ ret = call(*args)
65
+ raise FlowFailedException, ret if ret.errors.any?
66
+ ret
67
+ end
68
+
63
69
  def step_queue
64
70
  @step_queue ||= []
65
71
  end
@@ -0,0 +1,11 @@
1
+ module BusinessFlow
2
+ # Exception raised by DSL when flow execution fails
3
+ class FlowFailedException < RuntimeError
4
+ attr_reader :flow
5
+
6
+ def initialize(flow)
7
+ super("Failed execution of #{flow.class.name}")
8
+ @flow = flow
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module BusinessFlow
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.5.2'.freeze
3
3
  end
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.5.1
4
+ version: 0.5.2
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-27 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -174,6 +174,7 @@ files:
174
174
  - lib/business_flow/callable.rb
175
175
  - lib/business_flow/default_step_executor.rb
176
176
  - lib/business_flow/dsl.rb
177
+ - lib/business_flow/flow_failed_exception.rb
177
178
  - lib/business_flow/not_nil_validator.rb
178
179
  - lib/business_flow/step.rb
179
180
  - lib/business_flow/version.rb