Module: UnitMeasurements::Rails::Helpers

Defined in:
lib/unit_measurements/rails/helpers.rb

Overview

The UnitMeasurements::Rails::Helpers module provides helper methods for handling ActiveRecord models in the context of unit measurements.

Author:

Since:

  • 1.5.0

Instance Method Summary collapse

Instance Method Details

#column_exists?(column_name) ⇒ void

This method returns an undefined value.

Checks the existence of a column_name within the database table associated with the ActiveRecord model.

Examples:

Check if the height_quantity column exists in the database table:

column_exists?("height_quantity")

Parameters:

  • column_name (String)

    The name of the column to check for existence.

Raises:

  • (ArgumentError)

    If the specified column does not exist in the database table.

Author:

Since:

  • 1.5.0



28
29
30
31
32
# File 'lib/unit_measurements/rails/helpers.rb', line 28

def column_exists?(column_name)
  unless self.class.column_names.include?(column_name)
    raise ArgumentError, "Column '#{column_name}' does not exist in the database for table '#{self.class.table_name}'."
  end
end