Class: Tramway::Core::ApplicationRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Includes:
AASM, PgSearch::Model
Defined in:
app/models/tramway/core/application_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_extensionsObject



62
63
64
# File 'app/models/tramway/core/application_record.rb', line 62

def file_extensions
  @extensions
end

.human_attribute_name(attribute_name, *_args) ⇒ Object



36
37
38
39
40
41
42
43
# File 'app/models/tramway/core/application_record.rb', line 36

def human_attribute_name(attribute_name, *_args)
  excepted_attributes = %w[created_at updated_at]
  if attribute_name.to_s.in? excepted_attributes
    I18n.t "activerecord.attributes.tramway/core/application_record.#{attribute_name}"
  else
    super attribute_name
  end
end

.photo_versionsObject



58
59
60
# File 'app/models/tramway/core/application_record.rb', line 58

def photo_versions
  @versions
end

.search_by(*attributes, **associations) ⇒ Object



45
46
47
48
49
50
# File 'app/models/tramway/core/application_record.rb', line 45

def search_by(*attributes, **associations)
  pg_search_scope :full_text_search,
    against: attributes,
    associated_against: associations,
    using: i[tsearch trigram]
end

.state_machines_namesObject



66
67
68
# File 'app/models/tramway/core/application_record.rb', line 66

def state_machines_names
  AASM::StateMachineStore.fetch(self).machine_names
end

.uploader(attribute_name, uploader_name, **options) ⇒ Object



52
53
54
55
56
# File 'app/models/tramway/core/application_record.rb', line 52

def uploader(attribute_name, uploader_name, **options)
  mount_uploader attribute_name, "#{uploader_name.to_s.camelize}Uploader".constantize
  @versions = options[:versions] if uploader_name == :photo
  @extensions = options[:extensions]
end

Instance Method Details

#creatorObject



29
30
31
32
# File 'app/models/tramway/core/application_record.rb', line 29

def creator
  creation_event = audits.where(action: :create).first
  creation_event.user if creation_event.user_id.present?
end