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.



202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/roda/plugins/path.rb', line 202

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

#url(*args, &block) ⇒ Object

Similar to #path, but returns a complete URL.



216
217
218
# File 'lib/roda/plugins/path.rb', line 216

def url(*args, &block)
  "#{_base_url}#{path(*args, &block)}"
end