deas 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/deas/plugin.rb +38 -0
- data/lib/deas/version.rb +1 -1
- data/lib/deas/view_handler.rb +1 -2
- data/test/unit/plugin_tests.rb +95 -0
- data/test/unit/view_handler_tests.rb +2 -2
- metadata +7 -4
data/lib/deas/plugin.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Deas
|
2
|
+
module Plugin
|
3
|
+
|
4
|
+
# use the Plugin mixin to define your own custom plugins you want to mixin
|
5
|
+
# on your Deas view handlers. Define included hooks using `plugin_included`.
|
6
|
+
# this allows you to define multiple hooks separately and ensures the hooks
|
7
|
+
# will only be called once - even if your plugin is mixed in multiple times.
|
8
|
+
|
9
|
+
def self.included(receiver)
|
10
|
+
receiver.class_eval do
|
11
|
+
extend ClassMethods
|
12
|
+
|
13
|
+
# install an included hook that first checks if this plugin has
|
14
|
+
# already been installed on the reciever. If it has not been,
|
15
|
+
# class eval each callback on the receiver.
|
16
|
+
|
17
|
+
def self.included(plugin_receiver)
|
18
|
+
return if self.deas_plugin_receivers.include?(plugin_receiver)
|
19
|
+
|
20
|
+
self.deas_plugin_receivers.push(plugin_receiver)
|
21
|
+
self.deas_plugin_included_hooks.each do |hook|
|
22
|
+
plugin_receiver.class_eval(&hook)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
|
31
|
+
def deas_plugin_receivers; @plugin_receivers ||= []; end
|
32
|
+
def deas_plugin_included_hooks; @plugin_included_hooks ||= []; end
|
33
|
+
def plugin_included(&hook); self.deas_plugin_included_hooks << hook; end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/deas/version.rb
CHANGED
data/lib/deas/view_handler.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'deas/plugin'
|
3
|
+
|
4
|
+
module Deas::Plugin
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
TestPlugin = Module.new do
|
8
|
+
include Deas::Plugin
|
9
|
+
|
10
|
+
plugin_included{ inc_hook1 }
|
11
|
+
plugin_included{ inc_hook2 }
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Deas::Plugin"
|
15
|
+
setup do
|
16
|
+
@receiver = Class.new do
|
17
|
+
def self.inc_hook1; @hook1_count ||= 0; @hook1_count += 1; end
|
18
|
+
def self.hook1_count; @hook1_count ||= 0; end
|
19
|
+
def self.inc_hook2; @hook2_count ||= 0; @hook2_count += 1; end
|
20
|
+
def self.hook2_count; @hook2_count ||= 0; end
|
21
|
+
end
|
22
|
+
|
23
|
+
@hook1 = proc{ 1 }
|
24
|
+
@hook2 = proc{ 2 }
|
25
|
+
|
26
|
+
@plugin = Module.new{ include Deas::Plugin }
|
27
|
+
end
|
28
|
+
subject{ @plugin }
|
29
|
+
|
30
|
+
should have_imeths :deas_plugin_included_hooks, :deas_plugin_receivers
|
31
|
+
should have_imeths :plugin_included
|
32
|
+
|
33
|
+
should "have no plugin_included_hooks by default" do
|
34
|
+
assert_empty subject.deas_plugin_included_hooks
|
35
|
+
end
|
36
|
+
|
37
|
+
should "have no plugin_receivers by default" do
|
38
|
+
assert_empty subject.deas_plugin_receivers
|
39
|
+
end
|
40
|
+
|
41
|
+
should "append hooks with #plugin_included" do
|
42
|
+
subject.plugin_included(&@hook1)
|
43
|
+
subject.plugin_included(&@hook2)
|
44
|
+
|
45
|
+
assert_equal @hook1, subject.deas_plugin_included_hooks.first
|
46
|
+
assert_equal @hook2, subject.deas_plugin_included_hooks.last
|
47
|
+
end
|
48
|
+
|
49
|
+
should "call the plugin included hooks when mixed in" do
|
50
|
+
assert_equal 0, @receiver.hook1_count
|
51
|
+
assert_equal 0, @receiver.hook2_count
|
52
|
+
|
53
|
+
@receiver.send(:include, BaseTests::TestPlugin)
|
54
|
+
|
55
|
+
assert_equal 1, @receiver.hook1_count
|
56
|
+
assert_equal 1, @receiver.hook2_count
|
57
|
+
end
|
58
|
+
|
59
|
+
should "call hooks once when mixed in multiple times" do
|
60
|
+
@receiver.send(:include, BaseTests::TestPlugin)
|
61
|
+
|
62
|
+
assert_equal 1, @receiver.hook1_count
|
63
|
+
assert_equal 1, @receiver.hook2_count
|
64
|
+
|
65
|
+
@receiver.send(:include, BaseTests::TestPlugin)
|
66
|
+
|
67
|
+
assert_equal 1, @receiver.hook1_count
|
68
|
+
assert_equal 1, @receiver.hook2_count
|
69
|
+
end
|
70
|
+
|
71
|
+
should "call hooks once when mixed in by a 3rd party" do
|
72
|
+
third_party = Module.new do
|
73
|
+
def self.included(receiver)
|
74
|
+
receiver.send(:include, BaseTests::TestPlugin)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
@receiver.send(:include, third_party)
|
78
|
+
|
79
|
+
assert_equal 1, @receiver.hook1_count
|
80
|
+
assert_equal 1, @receiver.hook2_count
|
81
|
+
|
82
|
+
@receiver.send(:include, BaseTests::TestPlugin)
|
83
|
+
|
84
|
+
assert_equal 1, @receiver.hook1_count
|
85
|
+
assert_equal 1, @receiver.hook2_count
|
86
|
+
|
87
|
+
@receiver.send(:include, third_party)
|
88
|
+
|
89
|
+
assert_equal 1, @receiver.hook1_count
|
90
|
+
assert_equal 1, @receiver.hook2_count
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -37,10 +37,10 @@ module Deas::ViewHandler
|
|
37
37
|
handler_class = Class.new{ include Deas::ViewHandler }
|
38
38
|
|
39
39
|
handler_class.layout 'layouts/app'
|
40
|
-
assert_equal [
|
40
|
+
assert_equal ['layouts/app'], handler_class.layouts
|
41
41
|
|
42
42
|
handler_class.layouts 'layouts/web', 'layouts/search'
|
43
|
-
assert_equal [ 'layouts/web', 'layouts/search'
|
43
|
+
assert_equal ['layouts/app', 'layouts/web', 'layouts/search'], handler_class.layouts
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 95
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 16
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.16.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-06-01 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ns-options
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/deas/error_handler.rb
|
149
149
|
- lib/deas/exceptions.rb
|
150
150
|
- lib/deas/logging.rb
|
151
|
+
- lib/deas/plugin.rb
|
151
152
|
- lib/deas/rack_request_fix.rb
|
152
153
|
- lib/deas/redirect_handler.rb
|
153
154
|
- lib/deas/route.rb
|
@@ -184,6 +185,7 @@ files:
|
|
184
185
|
- test/unit/error_handler_tests.rb
|
185
186
|
- test/unit/exceptions_tests.rb
|
186
187
|
- test/unit/logging_tests.rb
|
188
|
+
- test/unit/plugin_tests.rb
|
187
189
|
- test/unit/redirect_handler_tests.rb
|
188
190
|
- test/unit/route_tests.rb
|
189
191
|
- test/unit/runner_tests.rb
|
@@ -251,6 +253,7 @@ test_files:
|
|
251
253
|
- test/unit/error_handler_tests.rb
|
252
254
|
- test/unit/exceptions_tests.rb
|
253
255
|
- test/unit/logging_tests.rb
|
256
|
+
- test/unit/plugin_tests.rb
|
254
257
|
- test/unit/redirect_handler_tests.rb
|
255
258
|
- test/unit/route_tests.rb
|
256
259
|
- test/unit/runner_tests.rb
|