Module: Frails::Utils

Defined in:
lib/frails/utils.rb

Class Method Summary collapse

Class Method Details

.camelize(term, first_letter = :upper, convert_slashes: true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/frails/utils.rb', line 5

def self.camelize(term, first_letter = :upper, convert_slashes: true)
  # If we are not converting slashes, and `first_letter` is `:lower`, this ensures that the
  # first letter after a slash is not capitalized.
  string = if !convert_slashes && first_letter == :lower
             term.split('/').map { |str| str.camelize :lower }.join('/')
           else
             term.camelize first_letter
           end

  # Reverses the effect of ActiveSupport::Inflector.camelize converting slashes into `::`. If
  # the keyword argument `convert_slashes:` is false (default: true), we can avoid
  # converting slashes to `::`.
  string.gsub!('::', '/') unless convert_slashes

  string
end