Class: Refinery::Resource

Inherits:
Core::BaseModel show all
Includes:
Refinery::Resources::Validators
Defined in:
resources/app/models/refinery/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::BaseModel

#users_manager

Class Method Details

.create_resources(params) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'resources/app/models/refinery/resource.rb', line 46

def create_resources(params)
  resources = []

  if params.present? and params[:file].is_a?(Array)
    params[:file].each do |resource|
      resources << create({:file => resource}.merge(params.except(:file)))
    end
  else
    resources << create(params)
  end

  resources
end

.per_page(dialog = false) ⇒ Object

How many resources per page should be displayed?



42
43
44
# File 'resources/app/models/refinery/resource.rb', line 42

def per_page(dialog = false)
  dialog ? Resources.pages_per_dialog : Resources.pages_per_admin_index
end

Instance Method Details

#cached_mime_typeObject



18
19
20
# File 'resources/app/models/refinery/resource.rb', line 18

def cached_mime_type
  @cached_mime_type ||= mime_type
end

#titleObject

Returns a titleized version of the filename my_file.pdf returns My File



29
30
31
# File 'resources/app/models/refinery/resource.rb', line 29

def title
  resource_title.presence || CGI::unescape(file_name.to_s).gsub(/\.\w+$/, '').titleize
end

#type_of_contentObject

used for searching



23
24
25
# File 'resources/app/models/refinery/resource.rb', line 23

def type_of_content
  cached_mime_type.split("/").join(" ")
end

#update_indexObject



33
34
35
36
37
38
# File 'resources/app/models/refinery/resource.rb', line 33

def update_index
  return if self.aai_config.disable_auto_indexing
  copy = self.dup.tap{ |r| r.file_uid = r.file_uid_was}
  self.class.index_remove(copy)
  self.class.index_add(self)
end