Sha256: 8eae0997273ed8ea75e5a2b99d5b4d707302d86e385fb079435fa39f5a8f6ae4

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

class Resource < ActiveRecord::Base

  # 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 & 2 rubygems

Version Path
refinerycms-resources-0.9.9.16 app/models/resource.rb
refinerycms-resources-0.9.9.15 app/models/resource.rb
refinerycms-resources-0.9.9.14 app/models/resource.rb
refinerycms-resources-0.9.9.13 app/models/resource.rb
refinerycms-resources-0.9.9.12 app/models/resource.rb
refinerycms-resources-0.9.9.11 app/models/resource.rb
refinerycms-resources-0.9.9.10 app/models/resource.rb
refinerycms-resources-0.9.9.9 app/models/resource.rb
refinerycms-resources-0.9.9.8 app/models/resource.rb
refinerycms-resources-0.9.9.7 app/models/resource.rb
refinerycms-resources-0.9.9.5 app/models/resource.rb
refinerycms-resources-0.9.9.4 app/models/resource.rb
refinerycms-resources-0.9.9.3 app/models/resource.rb
refinerycms-resources-0.9.9.2 app/models/resource.rb
refinerycms-resources-0.9.9.1 app/models/resource.rb
refinerycms-0.9.9 resources/app/models/resource.rb