Sha256: 5a888eaeb282c09510315ce2e93a88411208e29af3ed873722b7af0a7bbb9cd0
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
# -*- encoding: utf-8 -*- # -*- frozen_string_literal: true -*- # -*- warn_indent: true -*- module UnitMeasurements module Rails # The +UnitMeasurements::Rails::Helpers+ module provides helper methods for # handling +ActiveRecord+ models in the context of unit measurements. # # @author {Harshal V. Ladhe}[https://shivam091.github.io/] # @since 1.5.0 module Helpers # Checks the existence of a +column_name+ within the database table # associated with the +ActiveRecord+ model. # # @param [String] column_name The name of the column to check for existence. # # @raise [ArgumentError] # If the specified column does not exist in the database table. # # @example Check if the +height_quantity+ column exists in the database table: # column_exists?("height_quantity") # # @return [void] # # @author {Harshal V. Ladhe}[https://shivam091.github.io/] # @since 1.5.0 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 end end end # ActiveSupport hook to include ActiveRecord with the `UnitMeasurements::Rails::Helpers` # module. ActiveSupport.on_load(:active_record) do ::ActiveRecord::Base.send(:include, UnitMeasurements::Rails::Helpers) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unit_measurements-rails-1.6.0 | lib/unit_measurements/rails/helpers.rb |
unit_measurements-rails-1.5.0 | lib/unit_measurements/rails/helpers.rb |