business_flow 0.4.4 → 0.5.0

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: c64b686d7c5bc163fe6b12e9dbe8f697a93818be
4
- data.tar.gz: 3e689698a828b138adcacde97be3fd97724814ee
3
+ metadata.gz: 85e43bcbae90d26315e96c34809283cdd3d005e7
4
+ data.tar.gz: 60b353898bd32fe341670da5d73b119740c7adee
5
5
  SHA512:
6
- metadata.gz: 28e9939de69fa659e98f87e26fc7454fac38b597f6c985d6f47cb56249825752c0992596b282ae22b2f54111afc04cfdf52417ebe8336443918dac0762be52fc
7
- data.tar.gz: 4e72d98e7422b5c3738a82d9a7d127d41aaf11e9a8903b2d78966442928ea1429838a45ebfc8d1b26c30a866b567e67b5e07450f897b029794c080f414329b40
6
+ metadata.gz: 2d644ba4832a34c0f4358ded721396b1933242d074286ae626a7254003dfc2c034c6477ce57b78d963a8c8eb8d21bd3461ad2b7ad44d1a64d4875b784369e2c6
7
+ data.tar.gz: 8b221f9908a6935b60a4e8f95f982af448bab16996d133baefb68ff8094d0b483c622bba5a1d0fe9e2e8cfd42513c7a89e88a3b3c59b4c50579b860651c2e1ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business_flow (0.4.4)
4
+ business_flow (0.5.0)
5
5
  activemodel (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
 
@@ -74,6 +74,7 @@ GEM
74
74
  simplecov-html (~> 0.10.0)
75
75
  simplecov-html (0.10.2)
76
76
  thread_safe (0.3.6)
77
+ timecop (0.9.1)
77
78
  tzinfo (1.2.5)
78
79
  thread_safe (~> 0.1)
79
80
  unicode-display_width (1.3.0)
@@ -95,6 +96,7 @@ DEPENDENCIES
95
96
  rubocop (~> 0.53)
96
97
  rubocop-rspec (~> 1.24.0)
97
98
  simplecov (~> 0.15.1)
99
+ timecop (~> 0.9.1)
98
100
 
99
101
  BUNDLED WITH
100
102
  1.16.1
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'rubocop', '~> 0.53'
31
31
  spec.add_development_dependency 'rubocop-rspec', '~> 1.24.0'
32
32
  spec.add_development_dependency 'simplecov', '~> 0.15.1'
33
+ spec.add_development_dependency 'timecop', '~> 0.9.1'
33
34
  end
data/lib/business_flow.rb CHANGED
@@ -7,6 +7,7 @@ require 'business_flow/step'
7
7
  require 'business_flow/default_step_executor'
8
8
  require 'business_flow/dsl'
9
9
  require 'business_flow/base'
10
+ require 'business_flow/cacheable'
10
11
 
11
12
  # Makes the magic happen.
12
13
  module BusinessFlow
@@ -0,0 +1,52 @@
1
+ module BusinessFlow
2
+ # Extends the DSL to support caching of completed processes
3
+ module Cacheable
4
+ def self.included(klass)
5
+ klass.extend(ClassMethods)
6
+ end
7
+
8
+ def cache_key
9
+ "#{self.class.name}/#{self.class.cache_key.call(self, nil)}"
10
+ end
11
+
12
+ # DSL Methods
13
+ module ClassMethods
14
+ def cache_store(store = nil)
15
+ if store
16
+ @cache_store = store
17
+ else
18
+ @cache_store ||= ActiveSupport::Cache::MemoryStore.new
19
+ end
20
+ end
21
+
22
+ def cache_ttl(ttl = nil)
23
+ if ttl
24
+ @cache_ttl = ttl
25
+ else
26
+ @cache_ttl
27
+ end
28
+ end
29
+
30
+ def cache_key(key = nil)
31
+ if key
32
+ @cache_key = Callable.new(key, self)
33
+ else
34
+ @cache_key ||= Callable.new(:parameter_object, self)
35
+ end
36
+ end
37
+
38
+ # TODO: Make this some kind of private helper
39
+ def cache_options
40
+ options = { expires_in: cache_ttl }
41
+ options.tap(&:compact!)
42
+ end
43
+
44
+ def call(*args)
45
+ ret = new(*args)
46
+ cache_store.fetch(ret.cache_key, cache_options) do
47
+ ret.tap(&:call)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module BusinessFlow
2
- VERSION = '0.4.4'.freeze
2
+ VERSION = '0.5.0'.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.4.4
4
+ version: 0.5.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-20 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.15.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: timecop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.1
139
153
  description:
140
154
  email:
141
155
  - alex@teak.io
@@ -156,6 +170,7 @@ files:
156
170
  - business_flow.gemspec
157
171
  - lib/business_flow.rb
158
172
  - lib/business_flow/base.rb
173
+ - lib/business_flow/cacheable.rb
159
174
  - lib/business_flow/callable.rb
160
175
  - lib/business_flow/default_step_executor.rb
161
176
  - lib/business_flow/dsl.rb