Method: SimpleCommand::KlassTransform#to_constantized_class_string

Defined in:
lib/simple_command_dispatcher/klass_transform.rb

#to_constantized_class_string(klass, klass_modules = [], options = {}) ⇒ String

Returns a fully-qualified constantized class (as a string), given the klass and klass_modules.

Examples:


to_constantized_class_string("Authenticate", "Api") # => "Api::Authenticate"
to_constantized_class_string(:Authenticate, [:Api, :AppName, :V1]) # => "Api::AppName::V1::Authenticate"
to_constantized_class_string(:Authenticate, { :api :Api, app_name: :AppName, api_version: :V2 })
   # => "Api::AppName::V2::Authenticate"
to_constantized_class_string("authenticate", { :api :api, app_name: :app_name, api_version: :v1 },
   { class_titleize: true, module_titleize: true }) # => "Api::AppName::V1::Authenticate"

Parameters:

  • klass (Symbol or String)

    the class name.

  • klass_modules (Hash, Array or String) (defaults to: [])

    the modules klass belongs to.

  • options (Hash) (defaults to: {})

    the options that determine how klass_modules is transformed.

Options Hash (options):

  • :class_titleize (Boolean) — default: false

    Determines whether or not klass should be titleized.

  • :module_titleize (Boolean) — default: false

    Determines whether or not klass_modules should be titleized.

Returns:

  • (String)

    the fully qualified class, which includes module(s) and class name.



71
72
73
74
75
76
# File 'lib/simple_command_dispatcher/klass_transform.rb', line 71

def to_constantized_class_string(klass, klass_modules = [], options = {})
  options = ensure_options(options)
  klass_modules = to_modules_string(klass_modules, options)
  klass_string = to_class_string(klass, options)
  "#{klass_modules}#{klass_string}"
end