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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generator/support/naming.rb', line 22

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