Class: ContentStorageType
- Inherits:
-
Object
- Object
- ContentStorageType
- Includes:
- EnumField::DefineEnum
- Defined in:
- app/models/enums/content_storage_type.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Class Method Summary collapse
Instance Method Summary collapse
- #content_present? ⇒ Boolean
-
#initialize(code, fallback_slug = nil, _fallback_content = :main) ⇒ ContentStorageType
constructor
A new instance of ContentStorageType.
- #storage ⇒ Object
- #title ⇒ Object
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
#code ⇒ Object (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
17 18 19 |
# File 'app/models/enums/content_storage_type.rb', line 17 def content_present? ContentStorage.get(@code).present? end |
#storage ⇒ Object
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 |
#title ⇒ Object
13 14 15 |
# File 'app/models/enums/content_storage_type.rb', line 13 def title I18n.t(code, scope: [:content_storage_type]) end |