Sha256: 354ab92cc31184b9daef2d5c5ac3fab6b22390208708910e62badb65e557b10f

Contents?: true

Size: 1.1 KB

Versions: 45

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module EacRailsBase0
  module Patches
    module UrlForPatch
      class << self
        def included(base)
          base.include(InstanceMethods)
          base.alias_method_chain :url_for, :engines
        end
      end

      module InstanceMethods
        def url_for_with_engines(options = nil)
          url_for_without_engines(options)
        rescue ActionController::UrlGenerationError
          engines_url_for(options)
        end

        private

        def engines_url_for(options)
          ::Rails::Engine.subclasses.each do |engine|
            url = engine_url_for(engine, options)
            return url if url
          end
          raise ActionController::UrlGenerationError, "Options: #{options}"
        end

        def engine_url_for(engine, options)
          engine.routes.url_for(options)
        rescue ActionController::UrlGenerationError
          nil
        end
      end
    end
  end
end

patch = ::EacRailsBase0::Patches::UrlForPatch
target = ::ActionDispatch::Routing::UrlFor
target.send(:include, patch) unless target.included_modules.include?(patch)

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
eac_rails_base0-0.39.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.39.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.38.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.38.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.37.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.37.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.36.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.36.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.35.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.34.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.34.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.33.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.32.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.31.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.30.2 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.30.1 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.30.0 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.29.3 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.29.2 lib/eac_rails_base0/patches/url_for_patch.rb
eac_rails_base0-0.29.1 lib/eac_rails_base0/patches/url_for_patch.rb