class Excursion::Builders::UrlBuilder

Public Class Methods

new(app_name) click to toggle source
# File lib/excursion/builders/url_builder.rb, line 36
def initialize(app_name)
  @appname = app_name
end

Public Instance Methods

application() click to toggle source
# File lib/excursion/builders/url_builder.rb, line 5
def application
  Excursion::Pool.application(@appname)
end
method_missing(meth, *args) click to toggle source
Calls superclass method
# File lib/excursion/builders/url_builder.rb, line 17
def method_missing(meth, *args)
  route = application.route(route_name_from_method(meth))
  if route
    if meth.to_s.match(/_url\Z/)
      url_for(route, *args)
    elsif meth.to_s.match(/_path\Z/)
      replaced_path(route, *args)
    end
  else
    super
  end
end
respond_to_missing?(meth, include_private=false) click to toggle source
Calls superclass method
# File lib/excursion/builders/url_builder.rb, line 30
def respond_to_missing?(meth, include_private=false)
  !application.route(route_name_from_method(meth)).nil? || super
end
routes() click to toggle source
# File lib/excursion/builders/url_builder.rb, line 9
def routes
  application.routes
end
url_for(route, *args) click to toggle source
# File lib/excursion/builders/url_builder.rb, line 13
def url_for(route, *args)
  ActionDispatch::Http::URL.url_for(route_options(route, *args))
end

Protected Instance Methods

journey_utils_class() click to toggle source
# File lib/excursion/builders/url_builder.rb, line 63
def journey_utils_class
  if Excursion.rails3?
    Journey::Router::Utils
  elsif Excursion.rails4?
    ActionDispatch::Journey::Router::Utils
  end
end
replaced_path(route, *args) click to toggle source

Very hacky method to replace path parts with values

Needs work, particularly around formatting which is basically ignored right now.

# File lib/excursion/builders/url_builder.rb, line 52
def replaced_path(route, *args)
  path = route.path.spec.to_s.dup

  route.required_parts.zip(args) do |part, arg|
    path.gsub!(/(\*|:)#{part}/, journey_utils_class.escape_fragment(arg.to_param))
  end

  path.gsub!(/\(\.:format\)/, '') # This is really gross, and :format should actually be supported
  path
end
route_name_from_method(meth) click to toggle source
# File lib/excursion/builders/url_builder.rb, line 45
def route_name_from_method(meth)
  meth.to_s.gsub(/_(url|path)\Z/,'').to_sym
end
route_options(route, *args) click to toggle source
# File lib/excursion/builders/url_builder.rb, line 40
def route_options(route, *args)
  opts = args.extract_options!
  application.default_url_options.merge(opts).merge({path: replaced_path(route, *args)})
end