Class: Pageflow::FileType

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ FileType

Create file type to be returned in PageType#file_types.

Examples:


Pageflow::FileType.new(model: Pageflow::Rainbow::File,
                       editor_partial: 'pageflow/rainbow/editor/files/file')

Parameters:

  • options (Hash)

Options Hash (options):

  • :model (ActiveRecord::Base)

    Required. Model representing the file.

  • :editor_partial (String)

    Optional. Path of a partial to include in json representations of the file.

  • :collection_name (String)

    Optional. String to be used in routes. Defaults to ‘“pageflow_rainbow_file”` for model `Pageflow::Rainbow::File`.



36
37
38
39
40
# File 'lib/pageflow/file_type.rb', line 36

def initialize(options)
  @model = options.fetch(:model)
  @editor_partial = options.fetch(:editor_partial, nil)
  @collection_name = options.fetch(:collection_name, model.model_name.plural)
end

Instance Attribute Details

#collection_nameString (readonly)

Underscored plural name for usage in routes.

Returns:

  • (String)


19
20
21
# File 'lib/pageflow/file_type.rb', line 19

def collection_name
  @collection_name
end

#editor_partialString (readonly)

Path of the partial used to render a json representation of the file.

Returns:

  • (String)


15
16
17
# File 'lib/pageflow/file_type.rb', line 15

def editor_partial
  @editor_partial
end

#modelActiveRecord::Model (readonly)

ActiveRecord model that represents the files of this type.

Returns:

  • (ActiveRecord::Model)


10
11
12
# File 'lib/pageflow/file_type.rb', line 10

def model
  @model
end

Instance Method Details

#i18n_keyObject

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.



56
57
58
# File 'lib/pageflow/file_type.rb', line 56

def i18n_key
  model.model_name.i18n_key
end

#param_keyObject 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.



43
44
45
# File 'lib/pageflow/file_type.rb', line 43

def param_key
  model.model_name.param_key.to_sym
end

#type_nameObject

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.



51
52
53
# File 'lib/pageflow/file_type.rb', line 51

def type_name
  model.name
end