Class: Pageflow::FileTypes
- Inherits:
-
Object
- Object
- Pageflow::FileTypes
- Includes:
- Enumerable
- Defined in:
- lib/pageflow/file_types.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #find_by_collection_name!(collection_name) ⇒ Object
- #find_by_model!(model) ⇒ Object
-
#initialize(page_types) ⇒ FileTypes
constructor
A new instance of FileTypes.
- #with_css_background_image_support ⇒ Object
- #with_thumbnail_support ⇒ Object
Constructor Details
#initialize(page_types) ⇒ FileTypes
Returns a new instance of FileTypes.
5 6 7 |
# File 'lib/pageflow/file_types.rb', line 5 def initialize(page_types) @page_types = page_types end |
Instance Method Details
#each(&block) ⇒ Object
9 10 11 12 13 |
# File 'lib/pageflow/file_types.rb', line 9 def each(&block) first_level_file_types = @page_types.map(&:file_types).flatten lower_level_file_types = search_for_nested_file_types(first_level_file_types) (first_level_file_types + lower_level_file_types).uniq(&:model).each(&block) end |
#find_by_collection_name!(collection_name) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/pageflow/file_types.rb', line 15 def find_by_collection_name!(collection_name) detect do |file_type| file_type.collection_name == collection_name end || raise(FileType::NotFoundError, "No file type found for collection name '#{collection_name}'.") end |
#find_by_model!(model) ⇒ Object
22 23 24 25 26 |
# File 'lib/pageflow/file_types.rb', line 22 def find_by_model!(model) detect do |file_type| file_type.model == model end || raise(FileType::NotFoundError, "No file type found for '#{model.name}'.") end |
#with_css_background_image_support ⇒ Object
34 35 36 37 38 |
# File 'lib/pageflow/file_types.rb', line 34 def with_css_background_image_support select do |file_type| file_type.css_background_image_urls.present? end end |
#with_thumbnail_support ⇒ Object
28 29 30 31 32 |
# File 'lib/pageflow/file_types.rb', line 28 def with_thumbnail_support select do |file_type| file_type.model.instance_methods.include?(:thumbnail_url) end end |