has-guarded-handlers 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/has_guarded_handlers.rb +3 -1
- data/lib/has_guarded_handlers/version.rb +1 -1
- data/spec/has_guarded_handlers_spec.rb +9 -0
- metadata +15 -15
data/CHANGELOG.md
CHANGED
data/lib/has_guarded_handlers.rb
CHANGED
@@ -46,6 +46,8 @@ module HasGuardedHandlers
|
|
46
46
|
def guarded?(guards, event)
|
47
47
|
guards.find do |guard|
|
48
48
|
case guard
|
49
|
+
when Class
|
50
|
+
!event.is_a? guard
|
49
51
|
when Symbol
|
50
52
|
!event.__send__ guard
|
51
53
|
when Array
|
@@ -75,7 +77,7 @@ module HasGuardedHandlers
|
|
75
77
|
case guard
|
76
78
|
when Array
|
77
79
|
guard.each { |g| check_guards [g] }
|
78
|
-
when Symbol, Proc, Hash, String
|
80
|
+
when Class, Symbol, Proc, Hash, String
|
79
81
|
nil
|
80
82
|
else
|
81
83
|
raise "Bad guard: #{guard.inspect}"
|
@@ -50,6 +50,15 @@ describe TestObject do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe 'guards' do
|
53
|
+
it 'can be a class' do
|
54
|
+
class GuardedObject; end
|
55
|
+
response.expects(:call).once
|
56
|
+
subject.register_handler(:event, GuardedObject) { |_| response.call }
|
57
|
+
|
58
|
+
subject.trigger_handler :event, GuardedObject.new
|
59
|
+
subject.trigger_handler :event, Object.new
|
60
|
+
end
|
61
|
+
|
53
62
|
it 'can be a symbol' do
|
54
63
|
response.expects(:call).once
|
55
64
|
subject.register_handler(:event, :chat?) { |_| response.call }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has-guarded-handlers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ default_executable:
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
18
|
-
requirement: &
|
18
|
+
requirement: &2156641740 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 1.0.0
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *2156641740
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
|
-
requirement: &
|
29
|
+
requirement: &2156641100 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 2.5.0
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *2156641100
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: mocha
|
40
|
-
requirement: &
|
40
|
+
requirement: &2156640520 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *2156640520
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: ci_reporter
|
51
|
-
requirement: &
|
51
|
+
requirement: &2156639920 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: 1.6.3
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *2156639920
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: yard
|
62
|
-
requirement: &
|
62
|
+
requirement: &2156639320 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: 0.7.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *2156639320
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rake
|
73
|
-
requirement: &
|
73
|
+
requirement: &2156638720 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *2156638720
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: guard-rspec
|
84
|
-
requirement: &
|
84
|
+
requirement: &2156638220 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,7 +89,7 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *2156638220
|
93
93
|
description: Allow an object's API to provide flexible handler registration, storage
|
94
94
|
and matching to arbitrary events.
|
95
95
|
email:
|