Class: Watts::Path
- Inherits:
-
Object
- Object
- Watts::Path
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/watts.rb
Overview
You are unlikely to need to interact with this. It’s mainly for covering up the path-matching logic for Resources.
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
16 17 18 |
# File 'lib/watts.rb', line 16 def resource @resource end |
Instance Method Details
#match(path, args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/watts.rb', line 19 def match path, args if path.empty? [resource, args] if resource elsif(sub = self[path[0]]) sub.match(path[1..-1], args) else each { |k,sub| if k.kind_of?(Regexp) && k.match(path[0]) return sub.match(path[1..-1], args + [path[0]]) end } each { |k,sub| if k.kind_of?(Symbol) return sub.match(path[1..-1], args + [path[0]]) end } nil end end |
#rmatch(res, args, acc = []) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/watts.rb', line 39 def rmatch res, args, acc = [] return "/#{acc.join('/')}" if args.empty? && resource == res rest = args[1..-1] || [] accnext = acc.dup << args[0] each { |k,sub| if k.kind_of?(String) t = sub.rmatch res, args, acc + [k] return t if t elsif k.kind_of?(Regexp) && k.match(args[0]) t = sub.rmatch res, rest, accnext return t if t elsif k.kind_of?(Symbol) t = sub.rmatch res, rest, accnext return t if t end } nil end |