Skip to content

Commit

Permalink
Merge pull request #83 from krisleech/remove-deprecated-methods
Browse files Browse the repository at this point in the history
remove deprecated methods
  • Loading branch information
krisleech committed Oct 27, 2014
2 parents edfa701 + 20c1a6e commit c0ffd22
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 176 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased (!!contains breaking changes!!)

* remove deprecated methods

## 1.6.0 (25 Oct 2014)

Authors: Kris Leech
Expand Down
15 changes: 0 additions & 15 deletions lib/wisper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@
require 'wisper/broadcasters/logger_broadcaster'

module Wisper
def self.included(base)
warn "[DEPRECATION] `include Wisper::Publisher` instead of `include Wisper`"
base.class_eval { include Wisper::Publisher }
end

def self.with_listeners(*args, &block)
warn "[DEPRECATION] `use Wisper.subscribe` instead of `Wisper.with_listeners`"
self.subscribe(*args, &block)
end

def self.add_listener(listener, options = {})
warn "[DEPRECATION] `use Wisper.subscribe` instead of `Wisper.add_listener`"
self.subscribe(listener, options)
end

# Examples:
#
# Wisper.subscribe(AuditRecorder.new)
Expand Down
5 changes: 0 additions & 5 deletions lib/wisper/global_listeners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def self.clear
instance.clear
end

def self.add_listener(listener, options = {}) # deprecated
warn "[DEPRECATION] use `subscribe` instead of `add_listener`"
subscribe(listener, options)
end

private

def with_mutex
Expand Down
21 changes: 0 additions & 21 deletions lib/wisper/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,10 @@ def on(*events, &block)
self
end

def add_block_listener(options = {}, &block)
warn "[DEPRECATED] use `on` instead of `add_block_listener`"
local_registrations << BlockRegistration.new(block, options)
self
end

def add_listener(listener, options = {})
warn "[DEPRECATED] use `subscribe` instead of `add_listener`"
subscribe(listener, options)
end

def respond_to(*events, &block)
warn '[DEPRECATED] use `on` instead of `respond_to`'
on(*events, &block)
end

module ClassMethods
def subscribe(listener, options = {})
GlobalListeners.subscribe(listener, options.merge(:scope => self))
end

def add_listener(listener, options = {})
warn "[DEPRECATED] use `subscribe` instead of `add_listener`"
subscribe(listener, options)
end
end

private
Expand Down
9 changes: 0 additions & 9 deletions spec/lib/global_subscribers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,4 @@
Wisper::GlobalListeners.clear
expect(Wisper::GlobalListeners.listeners).to be_empty
end

describe 'backwards compatibility' do
it '.add_listener is aliased to .add' do
silence_warnings do
expect(Wisper::GlobalListeners).to receive(:subscribe)
Wisper::GlobalListeners.add_listener(global_listener)
end
end
end
end
84 changes: 0 additions & 84 deletions spec/lib/wisper/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,81 +214,6 @@
end
end

# @deprecated
describe '.add_listener' do
it 'is aliased to .subscribe' do
expect(publisher).to receive(:subscribe)
silence_warnings do
publisher.add_listener(listener)
end
end
end

# @deprecated
describe '.add_block_listener' do
let(:insider) { double('insider') }

it 'subscribes given block to all events' do
expect(insider).to receive(:it_happened).twice

silence_warnings do
publisher.add_block_listener do
insider.it_happened
end
end

publisher.send(:broadcast, 'something_happened')
publisher.send(:broadcast, 'and_so_did_this')
end

describe ':on argument' do
it '.add_block_listener subscribes block to an event' do
expect(insider).not_to receive(:it_happened).once

silence_warnings do
publisher.add_block_listener(:on => 'something_happened') do
insider.it_happened
end
end

publisher.send(:broadcast, 'something_happened')
publisher.send(:broadcast, 'and_so_did_this')
end

it '.add_block_listener subscribes block to all listed events' do
expect(insider).to receive(:it_happened).twice

silence_warnings do
publisher.add_block_listener(
:on => ['something_happened', 'and_so_did_this']) do
insider.it_happened
end
end

publisher.send(:broadcast, 'something_happened')
publisher.send(:broadcast, 'and_so_did_this')
publisher.send(:broadcast, 'but_not_this')
end
end

it 'returns publisher so methods can be chained' do
silence_warnings do
expect(publisher.add_block_listener(:on => 'this_thing_happened') do
end).to eq publisher
end
end
end

# @deprecated
describe '.respond_to (alternative block syntax)' do
it 'delegates to .on' do
expect(publisher).to receive(:on).with(:foobar)
silence_warnings do
publisher.respond_to(:foobar) { }
end
end
end

describe '.broadcast' do
it 'does not publish events which cannot be responded to' do
expect(listener).not_to receive(:so_did_this)
Expand Down Expand Up @@ -344,13 +269,4 @@
publisher_klass_2.new.send(:broadcast, 'it_happened')
end
end

describe '#add_listener' do # deprecated
it 'is aliased to #subscribe' do
expect(publisher).to receive(:subscribe)
silence_warnings do
publisher.add_listener(listener)
end
end
end
end
42 changes: 0 additions & 42 deletions spec/lib/wisper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
describe Wisper do
before do
# assign the stderr to a new StringIO to test errors
@orig_stderr, $stderr = $stderr, StringIO.new
end

after do
# reassign the stderr to the original <IO:<STDERR>> instead of StringIO
# used for testing
$stderr = @orig_stderr
end

it 'includes Wisper::Publisher for backwards compatibility' do
publisher_class = Class.new { include Wisper }
expect(publisher_class.ancestors).to include Wisper::Publisher

$stderr.rewind
expect($stderr.gets.chomp).to include 'DEPRECATION'
end

# NOTE .with_listeners is deprecated
it '.with_listeners subscribes listeners to all broadcast events for the duration of block' do
publisher = publisher_class.new
listener = double('listener')

Wisper.with_listeners(listener) do
publisher.send(:broadcast, 'im_here')
end

$stderr.rewind
expect($stderr.string.chomp).to include 'DEPRECATION'
end

# NOTE .add_listener is deprecated
it '.add_listener adds a global listener' do
listener = double('listener')

Wisper.add_listener(listener)

$stderr.rewind
expect($stderr.string.chomp).to include 'DEPRECATION'
end

describe '.subscribe' do
context 'given block' do
it 'subscribes listeners to all events for duration of the block' do
Expand Down

0 comments on commit c0ffd22

Please sign in to comment.