Should Flash::add_flash_types be public?

7 views
Skip to first unread message

Nuno Silva

unread,
Apr 10, 2017, 3:54:25 PM4/10/17
to Ruby on Rails: Talk
While playing around with gem `traceroute` (0.5.0) I noticed that my additional flash types:

# application_controller.rb
# ...
add_flash_types :success
add_flash_types :error
# ...

are "leaking" into public scope of every controller descendent of ApplicationController:

ApplicationController.new.method(:error).source_location
ApplicationController.new.method(:success).source_location

I wonder if add_flash_types should define the new methods as protected, since it might lead into conflicts with actual controller actions.
You can see this "leaking" with the gem or just with this:

ApplicationController.descendants.map { |ctrl| 
  ctrl.action_methods.map { |action| 
    ctrl.name + "#" + action
  }
}.flatten


This is trivial to accomplish - simply change it to:

#...
define_method(type) do
  request.flash[type]
end
protected type
helper_method type
#...

Reply all
Reply to author
Forward
0 new messages