Class: Excursion::Helpers::UrlHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/excursion/helpers/url_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/excursion/helpers/url_helper.rb', line 10

def method_missing(meth, *args)
  if meth.to_s.match(/\A(#{routes.collect { |name,route| name }.join("|")})_(url|path)\Z/)
    route = routes.get($1.to_sym)

    url_opts = @application.default_url_options.clone
    url_opts.merge!(args.slice!(args.length-1)) if args.last.is_a?(Hash) #&& args.last.has_key?(:host)
      
    return ActionDispatch::Http::URL.url_for(url_opts.merge({path: replaced_path(route, args)}))
    
    # This stuff is being deprecated.
    # We're transitioning towards using our custom path replacement and the uniform call to the base url_for method.

    #if Excursion.rails4?
      #ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.create(route, url_opts).call(Rails.application.routes, args)
    #elsif Excursion.rails3?
      # Playing with getting Rails3 working
      #mapping = ActionDispatch::Routing::Mapper::Mapping.new(routes, {}, routes.get($1.to_sym).path.spec.to_s.dup, {:controller => 'dummy', :action => 'dummy'})
      #puts mapping.send(:instance_variable_get, :@path)
    #end
  else
    super
  end
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



4
5
6
# File 'lib/excursion/helpers/url_helper.rb', line 4

def application
  @application
end

Instance Method Details

#respond_to_missing?(meth, include_private = false) ⇒ Boolean



34
35
36
# File 'lib/excursion/helpers/url_helper.rb', line 34

def respond_to_missing?(meth, include_private=false)
  meth.to_s.match(/\A(#{routes.collect { |name,route| name }.join("|")})_(url|path)\Z/) || super
end

#routesObject



6
7
8
# File 'lib/excursion/helpers/url_helper.rb', line 6

def routes
  @application.routes
end