gocardless/hutch — pull request #127 by gottfrois (2014-12-18 19:28:43+00:00)
Title: fix: connected? method to check actual broker connection state

Calling `Hutch.connect` on a closed connection will not make the broker re-connect.

Before:

```ruby
Hutch.connect
Hutch.publish('foo', 'bar')
puts Hutch.connected?

Hutch.broker.connection.close
puts Hutch.connected?

Hutch.connect
Hutch.publish('foo', 'bar')
```

Would result in the following stack trace:

```ruby
> Hutch.connect
=> true
> Hutch.publish('foo', 'bar')
2014-12-18T19:23:43Z 12293 INFO -- publishing message '"bar"' to foo
=> #
> puts Hutch.connected?
true
=> nil
> Hutch.broker.connection.close
=> :closed
> puts Hutch.connected?
true
=> nil
> Hutch.connect
=> nil
> Hutch.publish('foo', 'bar')
2014-12-18T19:23:43Z 12293 ERROR -- Unable to publish - connection is closed. Message: "bar", Routing key: foo.
Hutch::PublishError: Unable to publish - connection is closed. Message: "bar", Routing key: foo.
```

Now:

```ruby
> Hutch.connect
=> nil
> Hutch.publish('foo', 'bar')
2014-12-18T19:24:05Z 12386 INFO -- publishing message '"bar"' to foo
=> #
> puts Hutch.connected?
true
=> nil
> Hutch.broker.connection.close
=> :closed
> puts Hutch.connected?
false
=> nil
> Hutch.connect
=> nil
> Hutch.publish('foo', 'bar')
2014-12-18T19:24:06Z 12386 INFO -- publishing message '"bar"' to foo
```