class Restfulness::Route
Attributes
path[RW]
The path array of elements, :id always on end!
resource_name[RW]
Reference to the class that will handle requests for this route
Public Class Methods
new(*args)
click to toggle source
# File lib/restfulness/route.rb, line 11 def initialize(*args) self.resource_name = args.pop.to_s self.path = args.reject{|arg| arg == :id} if resource_name.empty? || resource.nil? # Try to load the resource raise ArgumentError, "Please provide a resource!" end end
Public Instance Methods
build_path(path)
click to toggle source
# File lib/restfulness/route.rb, line 20 def build_path(path) Path.new(self, path) end
build_resource(request, response)
click to toggle source
# File lib/restfulness/route.rb, line 42 def build_resource(request, response) resource.new(request, response) end
handles?(parts)
click to toggle source
# File lib/restfulness/route.rb, line 24 def handles?(parts) # Make sure same length (accounting for id) diff = parts.length - path.length return false if diff != 0 && diff != 1 # Compare the pairs path.each_with_index do |slug, i| if slug.is_a?(String) or slug.is_a?(Numeric) return false if parts[i] != slug.to_s end end true end
resource()
click to toggle source
# File lib/restfulness/route.rb, line 38 def resource resource_name.constantize end