lib/nyara/route.rb in nyara-0.1.pre.1 vs lib/nyara/route.rb in nyara-0.1.pre.2
- old
+ new
@@ -165,11 +165,11 @@
# class methods
class << Route
def routes
@routes || []
end
-
+
# #### Param
#
# * `controller` - string or class which inherits [Nyara::Controller](Controller.html)
#
# NOTE controller may be not defined when register_controller is called
@@ -238,13 +238,11 @@
end
def print_routes
puts "All routes:"
Nyara::Route.routes.each do |route|
- cname = route.controller.to_s
- cname.gsub!("Controller", "")
- cname.downcase!
+ cname = const2name route.controller
print "#{cname}#{route.id}".rjust(30), " "
print route.http_method_to_s.ljust(6), " "
print route.path_template
puts
end
@@ -258,9 +256,10 @@
name.gsub!(/[A-Z]/, &:downcase)
name
end
def name2const name
+ return Module.const_get(name) if name[0] =~ /[A-Z]/
name = name.gsub /(?<=\b|_)[a-z]/, &:upcase
name.gsub! '_', ''
name << 'Controller'
Module.const_get name
end