]> git.openstreetmap.org Git - rails.git/commitdiff
Use a lambda in order to pass parameters in before_actions
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 20 Mar 2019 14:07:33 +0000 (15:07 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 20 Mar 2019 14:08:36 +0000 (15:08 +0100)
This avoid calling methods on a new instance of the controller, and
therefore allows these methods to be marked as private.

As a bonus, rubocop can now parse them and warn when they refer to
actions that don't exist in the controller.

app/controllers/api/changesets_controller.rb
app/controllers/browse_controller.rb
app/controllers/changeset_comments_controller.rb
app/controllers/changesets_controller.rb

index 8841d4b3b23c8457b00664dd087da065b46e8d6e..fb6523f4e0065a1dd9c508fc2c9e490e68cbfaaa 100644 (file)
@@ -12,7 +12,6 @@ module Api
     before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
     before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe]
     before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :subscribe, :unsubscribe]
     before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
     before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe]
     before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :subscribe, :unsubscribe]
-    before_action(:only => [:index, :feed]) { |c| c.check_database_readable(true) }
     around_action :api_call_handle_error
     around_action :api_call_timeout, :except => [:upload]
 
     around_action :api_call_handle_error
     around_action :api_call_timeout, :except => [:upload]
 
index 0fccbb506bb2a19dae6db4087853a64b8f0933cf..ebdd2cd80fbbb2dfc812ae155477639215069e01 100644 (file)
@@ -3,7 +3,7 @@ class BrowseController < ApplicationController
 
   before_action :authorize_web
   before_action :set_locale
 
   before_action :authorize_web
   before_action :set_locale
-  before_action(:except => [:query]) { |c| c.check_database_readable(true) }
+  before_action -> { check_database_readable(true) }
   before_action :require_oauth
   around_action :web_timeout
   authorize_resource :class => false
   before_action :require_oauth
   around_action :web_timeout
   authorize_resource :class => false
index 05b28eacf01c9806759bcafa8138f33b5958ce44..4abffb90efafac72a7a1d662c5b06fd1d97eb78a 100644 (file)
@@ -4,7 +4,7 @@ class ChangesetCommentsController < ApplicationController
 
   authorize_resource
 
 
   authorize_resource
 
-  before_action(:only => [:index]) { |c| c.check_database_readable(true) }
+  before_action -> { check_database_readable(true) }
   around_action :web_timeout
 
   ##
   around_action :web_timeout
 
   ##
index fff9f543bf7f7dc3e95d0c49fa6f77e6267db466..32d9fd73314f53e731717081af5c383550298f8b 100644 (file)
@@ -7,7 +7,7 @@ class ChangesetsController < ApplicationController
   skip_before_action :verify_authenticity_token, :except => [:index]
   before_action :authorize_web
   before_action :set_locale
   skip_before_action :verify_authenticity_token, :except => [:index]
   before_action :authorize_web
   before_action :set_locale
-  before_action(:only => [:index, :feed]) { |c| c.check_database_readable(true) }
+  before_action -> { check_database_readable(true) }, :only => [:index, :feed]
 
   authorize_resource
 
 
   authorize_resource