Class: ContentStorageType

Inherits:
Object
  • Object
show all
Includes:
EnumField::DefineEnum
Defined in:
app/models/enums/content_storage_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, fallback_slug = nil, _fallback_content = :main) ⇒ ContentStorageType

Returns a new instance of ContentStorageType.



8
9
10
11
# File 'app/models/enums/content_storage_type.rb', line 8

def initialize(code, fallback_slug = nil, _fallback_content = :main)
  @code = code.to_sym
  @fallback_slug = fallback_slug || code.to_s
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'app/models/enums/content_storage_type.rb', line 6

def code
  @code
end

Class Method Details

.[](key) ⇒ Object



31
32
33
# File 'app/models/enums/content_storage_type.rb', line 31

def [](key)
  try(key)
end

Instance Method Details

#content_present?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/models/enums/content_storage_type.rb', line 17

def content_present?
  ContentStorage.get(@code).present?
end

#storageObject



21
22
23
24
# File 'app/models/enums/content_storage_type.rb', line 21

def storage
  ContentStorage.get(@code) || Structure.find_by(slug: @fallback_slug) ||
    ContentStorage.new(title: "\"#{title}\" - not found", content: "<!-- \"#{@code}\" (#{title}) not found! -->")
end

#titleObject



13
14
15
# File 'app/models/enums/content_storage_type.rb', line 13

def title
  I18n.t(code, scope: [:content_storage_type])
end