Skip to content

Commit

Permalink
Add subscribed? method to detect listener, bump to v1.1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathankleyn committed Sep 20, 2015
1 parent 2c1a827 commit aa09de7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion call_me_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH.unshift(File.join(__dir__, 'lib'))

Gem::Specification.new do |gem|
gem.name = 'call_me_ruby'
gem.version = '1.1.0'
gem.version = '1.1.1'
gem.homepage = 'https://github.com/nathankleyn/call_me_ruby'
gem.license = 'MIT'

Expand Down
4 changes: 4 additions & 0 deletions lib/call_me_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ def publish(name, *args)

true
end

def subscribed?(name)
self.class.class_callbacks.include?(name) || callbacks.include?(name)
end
end
18 changes: 18 additions & 0 deletions spec/lib/call_me_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,22 @@ def failure
subject.publish(:test)
end
end

describe('#subscribed?') do
it('returns true if an event is subscribed at the class level with the given name') do
subject.class.subscribe(:class_event, :success)

expect(subject.subscribed?(:class_event)).to be(true)
end

it('returns true if an event is subscribed at the instance level with the given name') do
subject.subscribe(:instance_event, :success)

expect(subject.subscribed?(:instance_event)).to be(true)
end

it('returns false if no events are subscribed with the given name') do
expect(subject.subscribed?(:failure)).to be(false)
end
end
end

0 comments on commit aa09de7

Please sign in to comment.