Module: FastCamelize::ActiveSupportInflectorPatch
- Defined in:
- lib/fast_camelize.rb
Overview
Override ActiveSupport::Inflector::camelize to use FastCamelize::camelize.
Instance Method Summary collapse
-
#camelize(string, uppercase_first_letter = true) ⇒ Object
Disabling rubocop here so that we can directly match the implementation in the Rails source, so it’s easier when Rails changes it.
Instance Method Details
#camelize(string, uppercase_first_letter = true) ⇒ Object
Disabling rubocop here so that we can directly match the implementation in the Rails source, so it’s easier when Rails changes it. rubocop:disable all
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fast_camelize.rb', line 17 def camelize(string, uppercase_first_letter = true) # This assignment is largely just here for type checking. This module is # always going to be included in ActiveSupport::Inflector, but rbs doesn't # have requires_ancestor-ish support yet. inflections = ActiveSupport::Inflector.inflections string = string.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { |match| inflections.acronyms[match] || match.capitalize } else string = string.sub(inflections.acronyms_camelize_regex) { |match| match.downcase } end FastCamelize.camelize(string, acronyms: inflections.acronyms) end |