Class: Pageflow::FileTypes
- Inherits:
-
Object
- Object
- Pageflow::FileTypes
- Includes:
- Enumerable
- Defined in:
- lib/pageflow/file_types.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #find_by_collection_name!(collection_name) ⇒ Object
- #find_by_model!(model) ⇒ Object
-
#initialize ⇒ FileTypes
constructor
A new instance of FileTypes.
- #register(file_type) ⇒ Object
- #with_css_background_image_support ⇒ Object
- #with_thumbnail_support ⇒ Object
Constructor Details
#initialize ⇒ FileTypes
Returns a new instance of FileTypes.
5 6 7 |
# File 'lib/pageflow/file_types.rb', line 5 def initialize @file_types = [] end |
Instance Method Details
#clear ⇒ Object
13 14 15 |
# File 'lib/pageflow/file_types.rb', line 13 def clear @file_types = [] end |
#each(&block) ⇒ Object
17 18 19 20 21 |
# File 'lib/pageflow/file_types.rb', line 17 def each(&block) first_level_file_types = trigger_lazy_loading_of_file_types 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
23 24 25 26 27 28 |
# File 'lib/pageflow/file_types.rb', line 23 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
30 31 32 33 34 |
# File 'lib/pageflow/file_types.rb', line 30 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 |
#register(file_type) ⇒ Object
9 10 11 |
# File 'lib/pageflow/file_types.rb', line 9 def register(file_type) @file_types << file_type end |
#with_css_background_image_support ⇒ Object
42 43 44 45 46 |
# File 'lib/pageflow/file_types.rb', line 42 def with_css_background_image_support select do |file_type| file_type.css_background_image_urls.present? end end |
#with_thumbnail_support ⇒ Object
36 37 38 39 40 |
# File 'lib/pageflow/file_types.rb', line 36 def with_thumbnail_support select do |file_type| file_type.model.instance_methods.include?(:thumbnail_url) end end |