Module: FastUnderscore::ActiveSupportInflectorOldPatch
- Defined in:
- lib/fast_underscore.rb
Overview
Override ActiveSupport::Inflector::underscore to use FastUnderscore::underscore for ActiveSupport < 5.2.0.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.pattern ⇒ Object
10 11 12 13 14 15 |
# File 'lib/fast_underscore.rb', line 10 def self.pattern return @pattern if defined?(@pattern) acronym_regex = ActiveSupport::Inflector.inflections.acronym_regex @pattern = /(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/ end |
Instance Method Details
#underscore(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fast_underscore.rb', line 17 def underscore(string) return string unless /[A-Z-]|::/.match?(string) response = string.dup response.gsub!(ActiveSupportInflectorOldPatch.pattern) do "#{$1 && "_"}#{$2.downcase}" end FastUnderscore.underscore(response) end |