Class: Pageflow::FileTypes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pageflow/file_types.rb

Instance Method Summary collapse

Constructor Details

#initializeFileTypes

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

#clearObject



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_supportObject



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_supportObject



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