Class: Waves::Resources::Paths

Inherits:
Object
  • Object
show all
Includes:
Waves::ResponseMixin
Defined in:
lib/resources/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Waves::ResponseMixin

#app, #app_name, #attributes, #basename, #captured, #extension, #log, #model, #model_name, #params, #paths, #query, #redirect, #render, #resource, #response, #traits

Constructor Details

#initialize(request) ⇒ Paths

Returns a new instance of Paths.



11
# File 'lib/resources/paths.rb', line 11

def initialize( request ) ; @request = request ; end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/resources/paths.rb', line 7

def request
  @request
end

Instance Method Details

#generate(template, args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/resources/paths.rb', line 13

def generate( template, args )
  return "/#{ args * '/' }" unless template.is_a?( Array ) and not template.empty?
  path = []
  ( "/#{ path * '/' }" ) if template.all? do | want |
    case want
    when true then path += args
    when String then path << want
    when Symbol then path << args.shift
    when Regexp then path << args.shift
    when Hash
      key, value = want.to_a.first
      case value
      when true then path += args
      when String, Symbol, RegExp then path << args.unshift
      end
    end
  end
end