Class: Refinery::Resource

Inherits:
Core::BaseModel show all
Extended by:
Mobility
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



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'resources/app/models/refinery/resource.rb', line 53

def create_resources(params)
  resources = []

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

  resources
end

.per_page(dialog = false) ⇒ Object

How many resources per page should be displayed?



49
50
51
# File 'resources/app/models/refinery/resource.rb', line 49

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

Instance Method Details

#cached_mime_typeObject



25
26
27
# File 'resources/app/models/refinery/resource.rb', line 25

def cached_mime_type
  @cached_mime_type ||= mime_type
end

#titleObject

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



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

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

#type_of_contentObject

used for searching



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

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

#update_indexObject



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

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