Method: Grape::DSL::Routing::ClassMethods#mount

Defined in:
lib/grape/dsl/routing.rb

#mount(mounts, opts = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/grape/dsl/routing.rb', line 82

def mount(mounts, opts = {})
  mounts = { mounts => '/' } unless mounts.respond_to?(:each_pair)
  mounts.each_pair do |app, path|
    if app.respond_to?(:mount_instance)
      mount(app.mount_instance(configuration: opts[:with] || {}) => path)
      next
    end
    in_setting = inheritable_setting

    if app.respond_to?(:inheritable_setting, true)
      mount_path = Grape::Router.normalize_path(path)
      app.top_level_setting.namespace_stackable[:mount_path] = mount_path

      app.inherit_settings(inheritable_setting)

      in_setting = app.top_level_setting

      app.change!
      change!
    end

    endpoints << Grape::Endpoint.new(
      in_setting,
      method: :any,
      path: path,
      app: app,
      route_options: { anchor: false },
      forward_match: !app.respond_to?(:inheritable_setting),
      for: self
    )
  end
end