Module: Upgrow::Naming

Extended by:
Naming
Included in:
Naming
Defined in:
lib/upgrow/naming.rb

Overview

Functions to derive constant names and other identifiers according to Upgrow’s conventions.

Instance Method Summary collapse

Instance Method Details

#model_to_record(model_name) ⇒ String

Convert a Model name to a Record name. The Record name by convention is the Model name with a ‘Record` suffix.

Parameters:

  • model_name (String)

    the Model name.

Returns:

  • (String)

    the Record name.



15
16
17
# File 'lib/upgrow/naming.rb', line 15

def model_to_record(model_name)
  "#{model_name}Record"
end

#record_to_model(record_name) ⇒ String

Convert a Record name to a Model name. The Model name by convention is the Record name without the ‘Record` suffix.

Parameters:

  • record_name (String)

    the Record name.

Returns:

  • (String)

    the Model name.



25
26
27
# File 'lib/upgrow/naming.rb', line 25

def record_to_model(record_name)
  record_name.delete_suffix('Record')
end

#repository_to_record(repository_name) ⇒ String

Convert a Repository name to a Record name. The Record name is inferred by the Repository name without the ‘Repository` suffix, and with the `Record` suffix added.

Parameters:

  • repository_name (String)

    the Repository name.

Returns:

  • (String)

    the Record name.



36
37
38
# File 'lib/upgrow/naming.rb', line 36

def repository_to_record(repository_name)
  "#{repository_name.delete_suffix("Repository")}Record"
end