<commit_before>module Redirectr
  REFERRER_PARAM_NAME = :referrer

  module ControllerMethods
    def self.included(base)
      base.send :include, InstanceMethods
      base.send :extend, ClassMethods

      base.send :helper_method,
        :current_path,
        :referrer_or_current_path,
        :back_or_default,
        :referrer_path,
        :referrer_param
    end

    module ClassMethods
      # Used to set a different param name where the referrer path should be stored.
      # Default is :referrer, a sensible alternative would be :r or so.
      # Example:
      #
      #   class MyController
      #     use_referrer_param_name :r
      #     # ...
      #   end
      #
      def use_referrer_param_name(new_name)
        const_set Redirectr::REFERRER_PARAM_NAME, new_name.to_sym
      end
    end

    module InstanceMethods

      # Return the name of the parameter used to pass the referrer path.
      # Use this instead of the real param name in creating your own links
      # to allow easily changing the name later
      # Example:
      #
      #  <%= link_to my_messages_path :filter_by => 'date', referrer_param => current_path %>
      #
      def referrer_param
        Redirectr::REFERRER_PARAM_NAME
      end

      # Return the path of the current request.
      # note that this path does NOT include any query parameters nor the hostname,
      # thus allowing you to navigate within the application only. This may be changed
      # in the future. If you need a different behaviour now, just overwrite this method
      # in your controller.
      # Example:
      #
      #  <%= link_to my_messages_path referrer_param => current_path %>
      #
      def current_path
        # maybe we want to use request.env['REQUEST_URI'] in the future...?
        request.env['PATH_INFO']
      end

      # Return the referrer or the current path, it the former is not set.
      # Useful in cases where there might be a redirect path that has to be
      # taken note of but in case it is not present, the current path will be
      # redirected back to.
      # Example:
      #
      #  <%= link_to my_messages_path referrer_param => referrer_or_current_path %>
      #
      def referrer_or_current_path
        referrer_path.blank? ? current_path : referrer_path
      end

      # Used in back links, referrer based redirection after actions etc.
      # Accepts a default redirect path in case no param[referrer_param]
      # is set, default being root_path.
      # To set an own default path (per controller), you can overwrite
      # the default_path method (see below).
      # Example:
      #
      #   class MyController
      #     def create
      #       @my = My.create(...)
      #       redirect_to back_or_default(my_path)
      #     end
      #   end
      #
      # The above example will redirect to the referrer_path if it is defined, otherwise
      # it will redirect to the my_path
      #
      # Example:
      #
      #   class MyController
      #     def create
      #       @my = My.create(...)
      #       redirect_to back_or_default
      #     end
      #   end
      #
      # The above example will redirect to the referrer_path if it is defined, otherwise
      # it will redirect to the root_path of the application.
      def back_or_default(default = nil)
        unless referrer_path.blank?
          referrer_path
        else
          default || default_path
        end
      end

      # to be overwritten by your controllers
      def default_path
        root_path
      end      
      
      # Convenience method for params[referrer_param]
      def referrer_path
        params[referrer_param]
      end
    end

  end

  module Helpers
    def self.included(base)
      base.send :include, InstanceMethods
    end
 
    module InstanceMethods
      # Create a link back to the path specified in the referrer-param.
      # title can be either a text string or anything else like an image.
      # Remember to call #html_safe on the title argument if it contains
      # HTML and you are using Rails 3.
      def link_to_back(title, options = {})
        link_to title, back_or_default, options
      end

      # Create a hidden input field containing the referrer or current path.
      # Handy for use in forms that are called with a referrer param which
      # has to be passed on and respected by the form processing action.
      def hidden_referrer_input_tag(options = {})
        hidden_field_tag :referrer, referrer_or_current_path, options
      end
    end

  end # module Helpers
end # module Redirectr

ActionController::Base.send :include, Redirectr::ControllerMethods
ActionView::Helpers.send :include, Redirectr::Helpers
ActionView::Base.send :include, Redirectr::Helpers<commit_msg>Remove deprecated warning messages from ActiveSupport::Concern<commit_after>module Redirectr
  REFERRER_PARAM_NAME = :referrer

  module ControllerMethods
    extend ActiveSupport::Concern

    included do
      helper_method :current_path,
                    :referrer_or_current_path,
                    :back_or_default,
                    :referrer_path,
                    :referrer_param
    end

    module ClassMethods
      # Used to set a different param name where the referrer path should be stored.
      # Default is :referrer, a sensible alternative would be :r or so.
      # Example:
      #
      #   class MyController
      #     use_referrer_param_name :r
      #     # ...
      #   end
      #
      def use_referrer_param_name(new_name)
        const_set Redirectr::REFERRER_PARAM_NAME, new_name.to_sym
      end
    end


    # Return the name of the parameter used to pass the referrer path.
    # Use this instead of the real param name in creating your own links
    # to allow easily changing the name later
    # Example:
    #
    #  <%= link_to my_messages_path :filter_by => 'date', referrer_param => current_path %>
    #
    def referrer_param
      Redirectr::REFERRER_PARAM_NAME
    end

    # Return the path of the current request.
    # note that this path does NOT include any query parameters nor the hostname,
    # thus allowing you to navigate within the application only. This may be changed
    # in the future. If you need a different behaviour now, just overwrite this method
    # in your controller.
    # Example:
    #
    #  <%= link_to my_messages_path referrer_param => current_path %>
    #
    def current_path
      # maybe we want to use request.env['REQUEST_URI'] in the future...?
      request.env['PATH_INFO']
    end

    # Return the referrer or the current path, it the former is not set.
    # Useful in cases where there might be a redirect path that has to be
    # taken note of but in case it is not present, the current path will be
    # redirected back to.
    # Example:
    #
    #  <%= link_to my_messages_path referrer_param => referrer_or_current_path %>
    #
    def referrer_or_current_path
      referrer_path.blank? ? current_path : referrer_path
    end

    # Used in back links, referrer based redirection after actions etc.
    # Accepts a default redirect path in case no param[referrer_param]
    # is set, default being root_path.
    # To set an own default path (per controller), you can overwrite
    # the default_path method (see below).
    # Example:
    #
    #   class MyController
    #     def create
    #       @my = My.create(...)
    #       redirect_to back_or_default(my_path)
    #     end
    #   end
    #
    # The above example will redirect to the referrer_path if it is defined, otherwise
    # it will redirect to the my_path
    #
    # Example:
    #
    #   class MyController
    #     def create
    #       @my = My.create(...)
    #       redirect_to back_or_default
    #     end
    #   end
    #
    # The above example will redirect to the referrer_path if it is defined, otherwise
    # it will redirect to the root_path of the application.
    def back_or_default(default = nil)
      unless referrer_path.blank?
        referrer_path
      else
        default || default_path
      end
    end

    # to be overwritten by your controllers
    def default_path
      root_path
    end

    # Convenience method for params[referrer_param]
    def referrer_path
      params[referrer_param]
    end
  end

  module Helpers
    extend ActiveSupport::Concern

    # Create a link back to the path specified in the referrer-param.
    # title can be either a text string or anything else like an image.
    # Remember to call #html_safe on the title argument if it contains
    # HTML and you are using Rails 3.
    def link_to_back(title, options = {})
      link_to title, back_or_default, options
    end

    # Create a hidden input field containing the referrer or current path.
    # Handy for use in forms that are called with a referrer param which
    # has to be passed on and respected by the form processing action.
    def hidden_referrer_input_tag(options = {})
      hidden_field_tag :referrer, referrer_or_current_path, options
    end
  end # module Helpers
end # module Redirectr

ActionController::Base.send :include, Redirectr::ControllerMethods
ActionView::Helpers.send :include, Redirectr::Helpers
ActionView::Base.send :include, Redirectr::Helpers
{'fraction_non_alphanumeric': 0.05748116254036598, 'fraction_numerical': 0.00021528525296017224, 'mean_word_length': 2.381004366812227, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2046897', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2588, 'n_words': 957}