Class: Forest::ApplicationRecord
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Forest::ApplicationRecord
show all
- Defined in:
- app/models/forest/application_record.rb
Direct Known Subclasses
BaseBlock, BlockKind, BlockLayout, BlockSlot, MediaItem, Menu, Page, Setting, Translation, User, UserGroup
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.cache_key ⇒ Object
26
27
28
29
30
|
# File 'app/models/forest/application_record.rb', line 26
def self.cache_key
Rails.cache.fetch self.cache_key_name do
SecureRandom.uuid
end
end
|
.cache_key_name ⇒ Object
22
23
24
|
# File 'app/models/forest/application_record.rb', line 22
def self.cache_key_name
"forest_all_#{model_name.plural}_cache_key"
end
|
.csv_columns ⇒ Object
32
33
34
35
|
# File 'app/models/forest/application_record.rb', line 32
def self.csv_columns
valid_columns = self.columns.select { |a| valid_csv_column_types.include?(a.type) }
valid_columns.collect(&:name) - invalid_csv_column_names
end
|
.expire_cache_key ⇒ Object
61
62
63
|
# File 'app/models/forest/application_record.rb', line 61
def self.expire_cache_key
Rails.cache.delete cache_key_name
end
|
.statusable? ⇒ Boolean
44
45
46
|
# File 'app/models/forest/application_record.rb', line 44
def self.statusable?
false
end
|
.to_csv_template ⇒ Object
37
38
39
40
41
|
# File 'app/models/forest/application_record.rb', line 37
def self.to_csv_template
CSV.generate(headers: true) do |csv|
csv << csv_columns
end
end
|
.versionable ⇒ Object
53
54
55
|
# File 'app/models/forest/application_record.rb', line 53
def self.versionable
false
end
|
Instance Method Details
#expire_cache_key ⇒ Object
65
66
67
|
# File 'app/models/forest/application_record.rb', line 65
def expire_cache_key
self.class.expire_cache_key
end
|
#statusable? ⇒ Boolean
48
49
50
|
# File 'app/models/forest/application_record.rb', line 48
def statusable?
false
end
|
#to_friendly_param ⇒ Object
Override this to define a friendly param attribute, like ‘slug` or `path`
70
71
72
|
# File 'app/models/forest/application_record.rb', line 70
def to_friendly_param
to_param
end
|
#to_label ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/models/forest/application_record.rb', line 74
def to_label
if try(:display_name).present?
display_name
elsif try(:name).present?
name
elsif try(:title).present?
title
else
"#{self.model_name.human} #{id}"
end
end
|
#to_select2_response ⇒ Object
86
87
88
89
90
91
|
# File 'app/models/forest/application_record.rb', line 86
def to_select2_response
if respond_to?(:media_item) && media_item.try(:attachment).present?
img_tag = "<img src='#{media_item.attachment.url(:thumb)}' style='height: 20px; display: inline-block; vertical-align: top;'> "
end
"#{img_tag}<span class='select2-response__id'>#{id}</span> #{to_label}"
end
|
#to_select2_selection ⇒ Object
93
94
95
|
# File 'app/models/forest/application_record.rb', line 93
def to_select2_selection
to_select2_response
end
|
#versionable ⇒ Object
57
58
59
|
# File 'app/models/forest/application_record.rb', line 57
def versionable
false
end
|