Module: Roda::RodaPlugins::Path::InstanceMethods
- Defined in:
- lib/roda/plugins/path.rb
Instance Method Summary collapse
-
#path(obj, *args, &block) ⇒ Object
Return a path based on the class of the object.
-
#url(*args, &block) ⇒ Object
Similar to #path, but returns a complete URL.
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.
223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/roda/plugins/path.rb', line 223 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.
237 238 239 |
# File 'lib/roda/plugins/path.rb', line 237 def url(*args, &block) "#{_base_url}#{path(*args, &block)}" end |