Module: SimpleCommandDispatcher::Helpers::Camelize
- Includes:
- TrimAll
- Included in:
- Services::CommandNamespaceService, Services::CommandService
- Defined in:
- lib/simple_command_dispatcher/helpers/camelize.rb
Instance Method Summary collapse
-
#camelize(token) ⇒ String
Transforms a RESTful route into a Ruby constant string for instantiation.
Methods included from TrimAll
Instance Method Details
#camelize(token) ⇒ String
Transforms a RESTful route into a Ruby constant string for instantiation
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simple_command_dispatcher/helpers/camelize.rb', line 20 def camelize(token) raise ArgumentError, 'Token is not a String' unless token.instance_of? String return if token.empty? # For RESTful paths → Ruby constants, use Rails' proven methods # They're fast, reliable, and handle edge cases that matter for constants result = trim_all(token) .gsub(%r{[/\-\.\s:]+}, '/') # Normalize separators to / .split('/') # Split into path segments .reject(&:empty?) # Remove empty segments .map { |segment| segment.underscore.camelize } # Rails camelization .join('::') # Join as Ruby namespace result.empty? ? '' : result end |