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
-
.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.
-
.class_name(name) ⇒ String
Convert a string to a Ruby class name with proper acronym handling.
-
.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.
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
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
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.
21 22 23 |
# File 'lib/generator/support/naming.rb', line 21 def parameter_name(param_name) param_name.underscore.gsub(/[^a-z0-9_]/, "_") end |