Sha256: 1b3d20f725634e5632ecedd6024b0a322b83f3a8000005476b15f34951259225

Contents?: true

Size: 530 Bytes

Versions: 10

Compression:

Stored size: 530 Bytes

Contents

module FileContainer
  mattr_reader :types
  
  @@types ||= []

  def self.included(base)
    return if @@types.include?(base)
    
    @@types << base
  
    base.instance_eval do
      include Associations
    end
  end

  def self.all
    @all ||= types.map{|t| t.where(1)} # lazy load :all of each type
  end

  module Associations
    def self.included(base)
      base.instance_eval do
        has_many :file_attachments, {
          :as => :attachable,
          :dependent => :destroy
        }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
file_share-0.1.16 app/models/file_container.rb
file_share-0.1.15 app/models/file_container.rb
file_share-0.1.13 app/models/file_container.rb
file_share-0.1.12 app/models/file_container.rb
file_share-0.1.11 app/models/file_container.rb
file_share-0.1.9 app/models/file_container.rb
file_share-0.1.8 app/models/file_container.rb
file_share-0.1.7 app/models/file_container.rb
file_share-0.1.6 app/models/file_container.rb
file_share-0.1.5 app/models/file_container.rb