lib/baurets/optionsful/introspections.rb in optionsful-0.2.3 vs lib/baurets/optionsful/introspections.rb in optionsful-0.3.0
- old
+ new
@@ -1,72 +1,24 @@
module Baurets
module Optionsful
module Introspections
- def self.is_part_static?(routes, index, value)
+ def self.do_the_matches(path_info)
+ routes = Rails.application.routes.routes if defined? Rails # Rails major = 3
+ routes.reject!{ |r| r.path == "/rails/info/properties" } # skip the route if it's internal info route
+ allow = ""
routes.each do |route|
- return true if route[0][index] == value
- end
- return false
-
- end
-
-
- def self.do_routing_introspection
- returning Array.new do |routes|
- route_requirements = nil
- ActionController::Routing::Routes.named_routes.map.each do |named_route|
- name = named_route[0].to_s
- routes << [[name], ["GET", named_route[1].requirements[:action]], {:controller => named_route[1].requirements[:controller], :action => named_route[1].requirements[:action]}]
- #TODO ANY ?!?
- end
- ActionController::Routing::Routes.routes.each do |route|
- static_path = []
- route.segments.each do |segment|
- route_requirements = route.requirements #TODO validate
- if segment.kind_of?(ActionController::Routing::StaticSegment)
- static_path << segment.value if (segment.respond_to?(:value) && segment.value != "/")
- elsif segment.kind_of?(ActionController::Routing::DynamicSegment)
- static_path << :dynamic unless (segment.respond_to?(:key) && segment.key == :format)
- end
+ if path_info =~ route.conditions[:path_info]
+ if route.verb
+ allow += (route.verb.to_s.upcase + "|") unless allow.include?(route.verb.to_s.upcase)
+ else
+ # TODO - return 'ANY' doesn't sound ANY good ;p
+ allow = "GET"
end
- routes << [static_path, [route.conditions[:method].to_s.upcase, route_requirements[:action]], route_requirements] unless route.conditions[:method].nil?
end
end
- end
-
- def self.guess_route(routes, path)
- guess = []
- parts = prepare_request_path(path)
- index = 0
- parts.each do |part|
- if is_part_static?(routes, index, part)
- guess << part
- else
- guess << :dynamic
- end
- index += 1
- end
- guess
- end
-
- def self.do_the_matches(routes, route_guess)
- allow = ""
- routes.each do |route|
- if route.first == route_guess
- allow += (route[1][0].to_s.upcase + "|") unless allow.include?(route[1][0].to_s.upcase)
- end
- end
allow = allow.split("|").join(", ")
end
- def self.prepare_request_path(path)
- path_parts = []
- path = path[0..(path.rindex('.')-1)] if path.include?('.')
- path_parts = path.split("/")
- path_parts.delete("")
- path_parts
- end
-
end
end
-end
\ No newline at end of file
+end