<commit_before>module Devise
  class CasActionUrlFactoryBase
    attr_reader :base_url, :mapping, :action

    def self.prepare_class
      Class.new(self) do
        include Rails.application.routes.url_helpers
        include Rails.application.routes.mounted_helpers if Rails.application.routes.try(:mounted_helpers)
      end
    end

    def initialize(base_url, mapping, action)
      @base_url = base_url
      @mapping  = mapping
      @action   = action
    end

    def call
      uri      = URI.parse(base_url).tap { |uri| uri.query = nil }
      uri.path = load_base_path
      uri.to_s
    end

    alias_method :build, :call

    private
    def load_base_path
      load_routes_path || load_mapping_path
    end

    def load_routes_path
      router_name = mapping.router_name || Devise.available_router_name<commit_msg>It seems like on some older versions of Rails, 'try' doesn't incorporate 'respond_to?' functionality, so let's do that check ourselves<commit_after>module Devise
  class CasActionUrlFactoryBase
    attr_reader :base_url, :mapping, :action

    def self.prepare_class
      Class.new(self) do
        include Rails.application.routes.url_helpers

        if Rails.application.routes.respond_to?(:mounted_helpers) && Rails.application.routes.mounted_helpers
          include Rails.application.routes.mounted_helpers
        end
      end
    end

    def initialize(base_url, mapping, action)
      @base_url = base_url
      @mapping  = mapping
      @action   = action
    end

    def call
      uri      = URI.parse(base_url).tap { |uri| uri.query = nil }
      uri.path = load_base_path
      uri.to_s
    end

    alias_method :build, :call

    private
    def load_base_path
      load_routes_path || load_mapping_path
    end

    def load_routes_path
      router_name = mapping.router_name || Devise.available_router_name
{'fraction_non_alphanumeric': 0.07020364415862808, 'fraction_numerical': 0.0, 'mean_word_length': 2.787018255578093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2890673', 'n_tokens_mistral': 574, 'n_tokens_neox': 561, 'n_words': 132}