bellbro 0.1.1 → 0.1.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: 74409ad9fa91aaa71560415ffed1edb0fbc7cd4a
4
- data.tar.gz: 804c467baf1edf241be682b8d745ce97755f5b9e
3
+ metadata.gz: 59843051a36bb5d7d2d9d22a261a9f2d5e71dbdd
4
+ data.tar.gz: 2f7c00567922a84937e26c9fa4b2682fabdcd7cd
5
5
  SHA512:
6
- metadata.gz: db86de1aeeb29d4f40c8da9ecbf895b43923c7b9ae6abdb347dd76e2c1e0593d70b11c2407ef927aefa041447734de8880e24f6dfe36196704c22041982b9a6d
7
- data.tar.gz: 4063b6d5ff173284fb7dfc267ac0d1652eb3a7c9a4437f90536cedc26d706b0c55c52ad680d7eda54b9d8affcaf51ad79c2d621894177a60b1d566c86556b20a
6
+ metadata.gz: 197c4375c817d11ad36058a9e28ca39ec1720e137cc0ac7ef574431affc94d4a9279047481073aa59fa8fdd83978f7980ebb1f659397fd6180bc0eebad339c77
7
+ data.tar.gz: 0b30b39693e8a51bbf596677c523e4e1bf2dc4dbe08e5ba29c637e2fae994b30453a8f740c8e1dc23817aa8338eb835a90ee7318f06c274f747971ab4dcd6b02
data/lib/bellbro/hooks.rb CHANGED
@@ -5,6 +5,14 @@ module Bellbro
5
5
  base.class_eval do
6
6
  extend ClassMethods
7
7
  end
8
+
9
+ def aborted?
10
+ !!@abort
11
+ end
12
+
13
+ def abort!
14
+ !(@abort = true)
15
+ end
8
16
  end
9
17
 
10
18
  module ClassMethods
@@ -125,6 +133,11 @@ module Bellbro
125
133
  hooks.each { |hook| after_hooks.unshift(hook) }
126
134
  end
127
135
 
136
+ def always(*hooks, &block)
137
+ hooks << block if block
138
+ hooks.each { |hook| always_hooks.unshift(hook) }
139
+ end
140
+
128
141
  # Internal: An Array of declared hooks to run around Worker
129
142
  # invocation. The hooks appear in the order in which they will be run.
130
143
  #
@@ -181,6 +194,11 @@ module Bellbro
181
194
  def after_hooks
182
195
  @after_hooks ||= []
183
196
  end
197
+
198
+ def always_hooks
199
+ @always_hooks ||= []
200
+ end
201
+
184
202
  end
185
203
 
186
204
  private
@@ -236,14 +254,21 @@ module Bellbro
236
254
  run_hooks(self.class.after_hooks)
237
255
  end
238
256
 
257
+ def run_always_hooks
258
+ run_hooks(self.class.always_hooks, halt_on_abort: false)
259
+ end
260
+
239
261
  # Internal: Run a colection of hooks. The "run_hooks" method is the common
240
262
  # interface by which collections of either before or after hooks are run.
241
263
  #
242
264
  # hooks - An Array of Symbol and Proc hooks.
243
265
  #
244
266
  # Returns nothing.
245
- def run_hooks(hooks)
246
- hooks.each { |hook| run_hook(hook) }
267
+ def run_hooks(hooks, halt_on_abort: true)
268
+ hooks.each do |hook|
269
+ run_hook(hook)
270
+ break if aborted? && halt_on_abort
271
+ end
247
272
  end
248
273
 
249
274
  # Internal: Run an individual hook. The "run_hook" method is the common
@@ -1,3 +1,3 @@
1
1
  module Bellbro
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -7,13 +7,18 @@ module Bellbro
7
7
 
8
8
  attr_reader :context
9
9
 
10
+ before :should_run?
11
+
10
12
  def perform(args)
11
13
  return unless args.present?
12
14
  set_context(args)
13
15
  run_before_hooks
14
- return unless should_run?
16
+ return if aborted?
15
17
  call
18
+ return if aborted?
16
19
  run_after_hooks
20
+ ensure
21
+ run_always_hooks
17
22
  end
18
23
 
19
24
  def call
@@ -21,8 +26,7 @@ module Bellbro
21
26
  end
22
27
 
23
28
  def should_run?
24
- # override
25
- self.class.should_run?
29
+ self.class.should_run? || abort!
26
30
  end
27
31
 
28
32
  def debug?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bellbro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Stokes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement