Module: Generator::Naming

Defined in:
lib/generator/support/naming.rb

Overview

Centralized naming conventions for generated code Handles class names, attribute names, and acronym transformations

Class Method Summary collapse

Class Method Details

.attribute_name(prop_name, prop_def = nil) ⇒ String

Convert a property name to a Ruby attribute name - Underscores the name - Strips "is_" prefix from boolean attributes for idiomatic Ruby

Parameters:

  • prop_name (String)

    the property name

  • prop_def (Hash) (defaults to: nil)

    the property definition (to check type)

Returns:

  • (String)

    snake_case attribute name



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generator/support/naming.rb', line 31

def attribute_name(prop_name, prop_def = nil)
  underscored = prop_name.underscore
  return underscored unless prop_def

  # Strip is_ prefix from boolean attributes for more idiomatic Ruby
  if prop_def["type"] == "boolean" || prop_def["type"] == "bool"
    underscored.sub(/^is_/, "")
  else
    underscored
  end
end

.class_name(name) ⇒ String

Convert a string to a Ruby class name with proper acronym handling

Parameters:

  • name (String)

    the name to convert (e.g., "api_client", "SKUInfo")

Returns:

  • (String)

    PascalCase class name with acronyms applied



11
12
13
14
# File 'lib/generator/support/naming.rb', line 11

def class_name(name)
  camelized = name.camelize
  Peddler::Acronyms.apply(camelized)
end

.parameter_name(param_name) ⇒ String

Convert an API parameter name to a Ruby identifier Amazon sometimes nests query parameters with dots (e.g., "carrierTracking.trackingNumber"), which underscore alone leaves as invalid Ruby.

Parameters:

  • param_name (String)

    the parameter name

Returns:

  • (String)

    snake_case identifier safe to use as a method parameter



21
22
23
# File 'lib/generator/support/naming.rb', line 21

def parameter_name(param_name)
  param_name.underscore.gsub(/[^a-z0-9_]/, "_")
end