Module: Roda::RodaPlugins::Path::InstanceMethods

Defined in:
lib/roda/plugins/path.rb

Instance Method Summary collapse

Instance Method Details

#path(obj, *args, &block) ⇒ Object

Return a path based on the class of the object. The object passed must have had its class previously registered with the application. If the app’s :add_script_name option is true, this prepends the SCRIPT_NAME to the path.



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/roda/plugins/path.rb', line 198

def path(obj, *args, &block)
  app = self.class
  opts = app.opts
  klass =  opts[:path_class_by_name] ? obj.class.name : obj.class
  unless meth = opts[:path_class_methods][klass]
    raise RodaError, "unrecognized object given to Roda#path: #{obj.inspect}"
  end

  path = send(meth, obj, *args, &block)
  path = request.script_name.to_s + path if opts[:add_script_name]
  path
end