Sha256: 8c4211557c0404314192a6735502de40d59f6addfe20b1d277d163a03e697355
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
module ErpTechSvcs module Extensions module ActiveRecord module HasFileAssets def self.included(base) base.extend(ClassMethods) end module ClassMethods def has_file_assets extend HasFileAssets::SingletonMethods include HasFileAssets::InstanceMethods has_many :files, :as => :file_asset_holder, :class_name => 'FileAsset', :dependent => :delete_all, :include => :capabilities end end module SingletonMethods end module InstanceMethods # Capabilites can be passed via a hash # { # :download => ['admin', 'employee'], # :edit => ['admin'] # } # def add_file(data, path=nil, capabilities=nil) file_asset = FileAsset.create!(:file_asset_holder => self, :base_path => path, :data => data) #set capabilites if they are passed capabilities.each do |capability_type, roles| file_asset.add_capability(capability_type, nil, roles) end if capabilities file_asset end def images self.files.where('type = ?', 'Image') end def templates self.files.where('type = ?', 'Template') end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
erp_tech_svcs-3.0.10 | lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb |
erp_tech_svcs-3.0.9 | lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb |