goat 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/goat.rb +26 -25
- metadata +3 -3
data/lib/goat.rb
CHANGED
@@ -271,8 +271,7 @@ module Goat
|
|
271
271
|
attr_accessor :app_class
|
272
272
|
|
273
273
|
def initialize
|
274
|
-
@
|
275
|
-
@after_handler_bindings = {}
|
274
|
+
@around_handler_bindings = {}
|
276
275
|
end
|
277
276
|
|
278
277
|
class ::Proc
|
@@ -306,25 +305,24 @@ module Goat
|
|
306
305
|
mappings[method][path] = hook
|
307
306
|
end
|
308
307
|
|
309
|
-
def
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
308
|
+
def around_handler_binding(handler, type)
|
309
|
+
if type == :before
|
310
|
+
@around_handler_bindings[handler] ||= App.bind(handler)
|
311
|
+
elsif type == :after
|
312
|
+
@around_handler_bindings[handler] ||= App.bind(handler, nil, false)
|
313
|
+
else
|
314
|
+
raise 'bad handler type'
|
315
|
+
end
|
316
|
+
end
|
316
317
|
|
317
|
-
def
|
318
|
-
app.class.
|
319
|
-
|
318
|
+
def run_around_handlers(app, type)
|
319
|
+
app.class.around_handlers.select{|h| h.first == type}.each do |handler|
|
320
|
+
around_handler_binding(handler[1], type).call(app)
|
320
321
|
end
|
321
322
|
end
|
322
323
|
|
323
|
-
def
|
324
|
-
|
325
|
-
after_handler_binding(handler).call(app)
|
326
|
-
end
|
327
|
-
end
|
324
|
+
def run_before_handlers(app); run_around_handlers(app, :before); end
|
325
|
+
def run_after_handlers(app); run_around_handlers(app, :after); end
|
328
326
|
|
329
327
|
def resp_for_error(e, app)
|
330
328
|
resp = nil
|
@@ -536,8 +534,7 @@ module Goat
|
|
536
534
|
@@not_found_handler = nil
|
537
535
|
@@active_pages = {}
|
538
536
|
@@active_page_queue = Queue.new
|
539
|
-
@@
|
540
|
-
@@after_handlers = []
|
537
|
+
@@around_handlers = []
|
541
538
|
|
542
539
|
def active_pages; @@active_pages; end
|
543
540
|
def active_page_queue; @@active_page_queue; end
|
@@ -584,15 +581,14 @@ module Goat
|
|
584
581
|
req_handler.add_mapping(opts)
|
585
582
|
end
|
586
583
|
|
587
|
-
def
|
588
|
-
def after_handlers; @@after_handlers; end
|
584
|
+
def around_handlers; @@around_handlers; end
|
589
585
|
|
590
586
|
def before(&blk)
|
591
|
-
|
587
|
+
around_handlers << [:before, blk]
|
592
588
|
end
|
593
589
|
|
594
590
|
def after(&blk)
|
595
|
-
|
591
|
+
around_handlers << [:after, blk]
|
596
592
|
end
|
597
593
|
|
598
594
|
def enable_notifications(opts={})
|
@@ -723,7 +719,7 @@ module Goat
|
|
723
719
|
include AppHelpers
|
724
720
|
include FlashHelper
|
725
721
|
|
726
|
-
def self.bind(hook, name=nil)
|
722
|
+
def self.bind(hook, name=nil, for_response=true)
|
727
723
|
mname = name || String.random
|
728
724
|
|
729
725
|
lambda do |app, *args|
|
@@ -736,7 +732,12 @@ module Goat
|
|
736
732
|
end
|
737
733
|
|
738
734
|
Logger.log :req, "running #{mname}"
|
739
|
-
|
735
|
+
if for_response
|
736
|
+
# sets the body
|
737
|
+
app.respond_with_hook(mname, *args)
|
738
|
+
else
|
739
|
+
app.send(mname, *args)
|
740
|
+
end
|
740
741
|
end
|
741
742
|
end
|
742
743
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 10
|
10
|
+
version: 0.2.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Collison
|