Class: Pageflow::FileType
- Inherits:
-
Object
- Object
- Pageflow::FileType
- Defined in:
- lib/pageflow/file_type.rb
Overview
Describes a type of file that can be managed in the editor and used in revisions.
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
-
#editor_partial ⇒ String
readonly
Path of a partial rendered in the json representation of the file inside the editor.
-
#nested_file_types ⇒ Array<FileType>
readonly
File types that are allowed to be nested inside the file.
-
#partial ⇒ String
readonly
Path of a partial rendered in the json representation of the file in both the editor and published entries.
-
#top_level_type ⇒ Boolean
readonly
Is this file type used in situations where it is not nested into another file type?.
-
#url_templates ⇒ #call
readonly
Callable that returns a hash of url template strings indexed by their names.
Instance Method Summary collapse
-
#collection_name ⇒ String
Underscored plural name for usage in routes.
- #i18n_key ⇒ Object private
-
#initialize(options) ⇒ FileType
constructor
Create file type to be returned in PageType#file_types.
-
#model ⇒ ActiveRecord::Model
ActiveRecord model that represents the files of this type.
- #param_key ⇒ Object (also: #short_name) private
- #type_name ⇒ Object private
Constructor Details
#initialize(options) ⇒ FileType
Create file type to be returned in PageType#file_types.
56 57 58 59 60 61 62 63 64 |
# File 'lib/pageflow/file_type.rb', line 56 def initialize() @model_string_or_reference = .fetch(:model) @partial = [:partial] @editor_partial = [:editor_partial] @collection_name_or_blank = [:collection_name] @nested_file_types = .fetch(:nested_file_types, []) @top_level_type = .fetch(:top_level_type, false) @url_templates = .fetch(:url_templates, ->() { {} }) end |
Instance Attribute Details
#editor_partial ⇒ String (readonly)
Path of a partial rendered in the json representation of the file inside the editor.
16 17 18 |
# File 'lib/pageflow/file_type.rb', line 16 def editor_partial @editor_partial end |
#nested_file_types ⇒ Array<FileType> (readonly)
File types that are allowed to be nested inside the file
20 21 22 |
# File 'lib/pageflow/file_type.rb', line 20 def nested_file_types @nested_file_types end |
#partial ⇒ String (readonly)
Path of a partial rendered in the json representation of the file in both the editor and published entries
11 12 13 |
# File 'lib/pageflow/file_type.rb', line 11 def partial @partial end |
#top_level_type ⇒ Boolean (readonly)
Is this file type used in situations where it is not nested into another file type?
25 26 27 |
# File 'lib/pageflow/file_type.rb', line 25 def top_level_type @top_level_type end |
#url_templates ⇒ #call (readonly)
Callable that returns a hash of url template strings indexed by their names.
30 31 32 |
# File 'lib/pageflow/file_type.rb', line 30 def url_templates @url_templates end |
Instance Method Details
#collection_name ⇒ String
Underscored plural name for usage in routes.
79 80 81 82 83 84 85 |
# File 'lib/pageflow/file_type.rb', line 79 def collection_name if @collection_name_or_blank.blank? model.model_name.plural else @collection_name_or_blank end end |
#i18n_key ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 |
# File 'lib/pageflow/file_type.rb', line 101 def i18n_key model.model_name.i18n_key end |
#model ⇒ ActiveRecord::Model
ActiveRecord model that represents the files of this type.
68 69 70 71 72 73 74 75 |
# File 'lib/pageflow/file_type.rb', line 68 def model @model ||= if @model_string_or_reference.is_a?(String) @model_string_or_reference.constantize else @model_string_or_reference end end |
#param_key ⇒ Object Also known as: short_name
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/pageflow/file_type.rb', line 88 def param_key model.model_name.param_key.to_sym end |
#type_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/pageflow/file_type.rb', line 96 def type_name model.name end |