Skip to content

Commit

Permalink
airbrake-ruby: deprecate notifier_name argument
Browse files Browse the repository at this point in the history
Partially resolves #165 (Get rid of third argument in public API
methods)
  • Loading branch information
kyrylo committed Feb 20, 2017
1 parent d750873 commit 47fecfc
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Airbrake Ruby Changelog

### master

* **IMPORTANT:** Deprecate `notifier_name` argument for all public API methods
such as `Airbrake.notify('oops', {}, :my_notifier)`
([#168](https://github.com/airbrake/airbrake/pull/168))

### [v1.7.1][v1.7.1] (February 3, 2017)

* **IMPORTANT:** fixed bug when `blacklist_keys/whitelist_keys` does not filter
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ end
params = { time: Time.now }

# Send an exception to Project A.
Airbrake.notify('Oops!', params, :project_a)
Airbrake[:project_a].notify('Oops!', params)

# Send an exception to Project B.
Airbrake.notify('Oops!', params, :project_b)
Airbrake[:project_b].notify('Oops!', params)

# Wait for the notifiers to finish their work and make them inactive.
%i(project_a project_b).each { |notifier| Airbrake.close(notifier) }
%i(project_a project_b).each { |notifier_name| Airbrake[notifier_name].close }
```

Configuration
Expand Down Expand Up @@ -401,6 +401,14 @@ API

### Airbrake

#### Airbrake.[]

Retrieves a configured notifier.

```ruby
Airbrake[:my_notifier] #=> Airbrake::Notifier
```

#### Airbrake.notify

Sends an exception to Airbrake asynchronously.
Expand Down Expand Up @@ -545,7 +553,7 @@ at_exit do
Airbrake.close

# Closes a named notifier.
Airbrake.close(:my_notifier)
Airbrake[:my_notifier].close
end
```

Expand Down
80 changes: 73 additions & 7 deletions lib/airbrake-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#
# # Send an exception via other configured notifier.
# params = {}
# Airbrake.notify('Oops', params, :my_other_project)
# Airbrake[:my_other_project].notify('Oops', params)
#
# @see Airbrake::Notifier
# @since v1.0.0
Expand All @@ -77,6 +77,18 @@ module Airbrake
@notifiers = {}

class << self
##
# Retrieves configured notifiers.
#
# @example
# Airbrake[:my_notifier].notify('oops')
#
# @return [Airbrake::Notifier, nil]
# @since v1.8.0
def [](notifier_name)
@notifiers[notifier_name]
end

##
# Configures a new +notifier+ with the given name. If the name is not given,
# configures the default notifier.
Expand Down Expand Up @@ -139,7 +151,16 @@ def configure(notifier = :default)
# tab in your project's dashboard
# @return [Airbrake::Promise]
# @see .notify_sync
def notify(exception, params = {}, notifier = :default)
def notify(exception, params = {}, notifier = (no_arg = true && :default))
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.notify` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same methods directly on it."
)
end
call_notifier(notifier, __method__, exception, params)
end

Expand All @@ -153,7 +174,16 @@ def notify(exception, params = {}, notifier = :default)
#
# @return [Hash{String=>String}] the reponse from the server
# @see .notify
def notify_sync(exception, params = {}, notifier = :default)
def notify_sync(exception, params = {}, notifier = (no_arg = true && :default))
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.notify_sync` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same methods directly on it."
)
end
call_notifier(notifier, __method__, exception, params)
end

Expand Down Expand Up @@ -184,7 +214,16 @@ def notify_sync(exception, params = {}, notifier = :default)
# @yieldreturn [void]
# @return [void]
# @note Once a filter was added, there's no way to delete it
def add_filter(filter = nil, notifier = :default, &block)
def add_filter(filter = nil, notifier = (no_arg = true && :default), &block)
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.add_filter` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same same methods directly on it."
)
end
call_notifier(notifier, __method__, filter, &block)
end

Expand All @@ -204,7 +243,16 @@ def add_filter(filter = nil, notifier = :default, &block)
# @param [Hash] params The additional params attached to the notice
# @return [Airbrake::Notice] the notice built with help of the given
# arguments
def build_notice(exception, params = {}, notifier = :default)
def build_notice(exception, params = {}, notifier = (no_arg = true && :default))
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.build_notice` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same methods directly on it."
)
end
call_notifier(notifier, __method__, exception, params)
end

Expand All @@ -219,7 +267,16 @@ def build_notice(exception, params = {}, notifier = :default)
# Airbrake.notify('App crashed!') #=> raises Airbrake::Error
#
# @return [void]
def close(notifier = :default)
def close(notifier = (no_arg = true && :default))
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.close` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same methods directly on it."
)
end
call_notifier(notifier, __method__)
end

Expand All @@ -235,7 +292,16 @@ def close(notifier = :default)
# @option deploy_params [Symbol] :revision
# @option deploy_params [Symbol] :version
# @return [void]
def create_deploy(deploy_params, notifier = :default)
def create_deploy(deploy_params, notifier = (no_arg = true && :default))
unless no_arg
warn(
"#{LOG_LABEL} `Airbrake.create_deploy` method signature was changed. " \
"Passing `notifier_name` is deprecated and will be removed in the " \
"next MAJOR release.\n" \
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
"and call same methods directly on it."
)
end
call_notifier(notifier, __method__, deploy_params)
end

Expand Down
1 change: 0 additions & 1 deletion lib/airbrake-ruby/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Airbrake
# synchronous and asynchronous delivery.
#
# @see Airbrake::Config The list of options
# @api private
# @since v1.0.0
class Notifier
##
Expand Down

0 comments on commit 47fecfc

Please sign in to comment.