Module: Autoloaded::Inflection Private

Defined in:
lib/autoloaded/inflection.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Translates source filenames into constants.

Since:

  • 1.3

Class Method Summary collapse

Class Method Details

.to_constant_name(source_filename) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Directories are ignored rather than translated into namespaces.

Translates a String representing a source filename into a Symbol representing a constant.

Parameters:

  • source_filename (String)

    the name of a source code file

Returns:

  • (Symbol)

    the name of a constant corresponding to source_filename

Raises:

  • (ArgumentError)

    source_filename is nil or empty

Since:

  • 1.3



18
19
20
21
22
23
24
25
26
27
# File 'lib/autoloaded/inflection.rb', line 18

def self.to_constant_name(source_filename)
  source_filename = source_filename.to_s
  raise(::ArgumentError, "can't be blank") if source_filename.empty?

  translate(source_filename, *[:file_basename,
                               :camelize_if_lowercase,
                               :nonalphanumeric_to_underscore,
                               :delete_leading_nonalphabetic,
                               :capitalize_first]).to_sym
end