Sha256: d30fa8f08ab848253a0f9626360090a986958f721d97087e1af1ef0fb8cab9eb

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

class Resource < ActiveRecord::Base

  attr_accessible :id, :file
  # What is the max resource size a user can upload
  MAX_SIZE_IN_MB = 50

  resource_accessor :file

  validates :file, :presence => {},
                   :length   => { :maximum => MAX_SIZE_IN_MB.megabytes }

   # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
   acts_as_indexed :fields => [:file_name, :title, :type_of_content]

  # when a dialog pops up with resources, how many resources per page should there be
  PAGES_PER_DIALOG = 12

  # when listing resources out in the admin area, how many resources should show per page
  PAGES_PER_ADMIN_INDEX = 20

  delegate :ext, :size, :mime_type, :url, :to => :file

  # used for searching
  def type_of_content
    mime_type.split("/").join(" ")
  end

  # Returns a titleized version of the filename
  # my_file.pdf returns My File
  def title
    CGI::unescape(file_name.to_s).gsub(/\.\w+$/, '').titleize
  end

  class << self
    # How many resources per page should be displayed?
    def per_page(dialog = false)
      dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
    end

    def create_resources(params)
      resources = []

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

      resources
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
refinerycms-resources-1.0.11 app/models/resource.rb
refinerycms-resources-1.0.10 app/models/resource.rb
refinerycms-resources-1.0.9 app/models/resource.rb
refinerycms-resources-1.0.8 app/models/resource.rb
refinerycms-resources-1.0.7 app/models/resource.rb
refinerycms-resources-1.0.5 app/models/resource.rb
refinerycms-resources-1.0.4 app/models/resource.rb
refinerycms-resources-1.0.3 app/models/resource.rb
refinerycms-resources-1.0.1 app/models/resource.rb
refinerycms-resources-1.0.0 app/models/resource.rb
refinerycms-resources-0.9.9.22 app/models/resource.rb
refinerycms-resources-0.9.9.21 app/models/resource.rb
refinerycms-resources-0.9.9.20 app/models/resource.rb
refinerycms-resources-0.9.9.19 app/models/resource.rb
refinerycms-resources-0.9.9.18 app/models/resource.rb
refinerycms-resources-0.9.9.17 app/models/resource.rb