Sha256: 104f763c012d6ed5e339c358fe293640da003ef2a87803ee276917f6ef716ec7
Contents?: true
Size: 884 Bytes
Versions: 6
Compression:
Stored size: 884 Bytes
Contents
class Rage::Router::Util class << self # converts controller name in a path form into a class # `api/v1/users` => `Api::V1::UsersController` def path_to_class(str) str = str.capitalize str.gsub!(/([\/_])([a-zA-Z0-9]+)/) do if $1 == "/" "::#{$2.capitalize}" else $2.capitalize end end klass = "#{str}Controller" if Object.const_defined?(klass) Object.const_get(klass) else raise Rage::Errors::RouterError, "Routing error: could not find the #{klass} class" end end @@names_map = {} # converts controller name in a path form into a string representation of a class # `api/v1/users` => `"Api::V1::UsersController"` def path_to_name(str) @@names_map[str] || begin @@names_map[str] = path_to_class(str).name end end end end
Version data entries
6 entries across 6 versions & 1 rubygems