Class: Glib::ApplicationRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
EnumHumanization, EnumSymbolization
Defined in:
app/models/glib/application_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnumSymbolization

backing_type

Methods included from EnumHumanization

#glib_enum_humanize

Class Method Details

.glib_has_one_attached(field_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/glib/application_record.rb', line 18

def self.glib_has_one_attached(field_name)
  has_one_attached field_name

  define_method("#{field_name}=") do |value|
    if value == ''
      send(field_name).detach
    else
      super(value)
    end
  end
end

Instance Method Details

#assert_core_columns_existObject



30
31
32
33
34
35
36
37
38
# File 'app/models/glib/application_record.rb', line 30

def assert_core_columns_exist
  if Rails.env.development? || Rails.env.test?
    [:id, :created_at, :updated_at].each do |column_name|
      unless self.class.column_names.include?(column_name.to_s)
        raise ActiveRecord::ConfigurationError, "#{self.class.table_name}.#{column_name} should exist"
      end
    end
  end
end