Skip to content

Commit

Permalink
Retrieve controller/action from payload hash
Browse files Browse the repository at this point in the history
We were unnecessarily retrieving the controller and action parameters
from the nested `params` when we could simply retrieve it from the
top-level payload.

Closes #172.
  • Loading branch information
benlovell committed Mar 3, 2016
1 parent 39ad590 commit cd2dc08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/lograge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def before_format(data, payload)

def ignore_actions(actions)
ignore(lambda do |event|
params = event.payload[:params]
Array(actions).include?("#{params['controller']}##{params['action']}")
params = event.payload
Array(actions).include?("#{params[:controller]}##{params[:action]}")
end)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/lograge/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def initial_data(payload)
method: payload[:method],
path: extract_path(payload),
format: extract_format(payload),
controller: payload[:params]['controller'],
action: payload[:params]['action']
controller: payload[:controller],
action: payload[:action]
}
end

Expand Down
4 changes: 3 additions & 1 deletion spec/lograge_logsubscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:subscriber) { Lograge::RequestLogSubscriber.new }
let(:event_params) { { 'controller' => 'home', 'action' => 'index', 'foo' => 'bar' } }
let(:event_params) { { 'foo' => 'bar' } }

let(:event) do
ActiveSupport::Notifications::Event.new(
Expand All @@ -21,6 +21,8 @@
Time.now,
2,
status: 200,
controller: 'home',
action: 'index',
format: 'application/json',
method: 'GET',
path: '/home?foo=bar',
Expand Down

0 comments on commit cd2dc08

Please sign in to comment.