Sha256: 669b5cd131c6a4ad2635596d9236b97c7d6fd755d074d5620c7401aec61486ed
Contents?: true
Size: 1.05 KB
Versions: 11
Compression:
Stored size: 1.05 KB
Contents
module Restfulness class Route # The path array of elements, :id always on end! attr_accessor :path # Reference to the class that will handle requests for this route attr_accessor :resource_name 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 def build_path(path) Path.new(self, path) end 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 def resource resource_name.constantize end def build_resource(request, response) resource.new(request, response) end end end
Version data entries
11 entries across 11 versions & 1 rubygems