Module: Jets::Router::Dsl::Mount

Included in:
Jets::Router::Dsl
Defined in:
lib/jets/router/dsl/mount.rb

Instance Method Summary collapse

Instance Method Details

#mount(*args) ⇒ Object

support these notations:

mount Blorgh::Engine, at: "/blog"
mount sprockets_env => "/assets"
mount sprockets_env => "/assets", internal: true


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jets/router/dsl/mount.rb', line 7

def mount(*args)
  options = args.extract_options!

  if args.empty?
    mount_option = options.find { |k,v| !k.is_a?(String) && !v.is_a?(Symbol) }
    mount_class, at = mount_option[0], mount_option[1]
  else
    mount_class = args.first
    at = options[:at]
  end

  at = "/#{at}" unless at.starts_with?("/")
  mount_class_at(mount_class, options.merge(at: at))
end

#mount_class_at(klass, options = {}) ⇒ Object

The mounted class must be a Rack compatiable class



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jets/router/dsl/mount.rb', line 23

def mount_class_at(klass, options={})
  if klass.is_a?(Class) && klass < Jets::Engine
    mount_engine(klass, options)
  else
    # Handles mount like Sprockets::Environment.new
    at = options.delete(:at)
    at = at[1..-1] if at.starts_with?('/') # be more forgiving if / accidentally included
    at_wildcard = at.blank? ? "*path" : "#{at}/*path"
    options.merge!(to: "jets/mount#call", mount_class: klass)

    any at, options
    any at_wildcard, options
  end
end

#mount_engine(klass, options = {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/jets/router/dsl/mount.rb', line 40

def mount_engine(klass, options={})
  at = options.delete(:at)
  options.merge!(engine: klass, path: at)
  create_route(options)
  @@mounted_engines[at] = klass
end