Module: ErpTechSvcs::Extensions::ActiveRecord::HasFileAssets::InstanceMethods

Defined in:
lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb

Instance Method Summary collapse

Instance Method Details

#add_file(data, path = nil, capabilities = nil) ⇒ Object

Capabilites can be passed via a hash

:download => ['admin', 'employee'],
:edit     => ['admin']



30
31
32
33
34
35
36
37
38
39
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 30

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

#imagesObject



41
42
43
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 41

def images
						self.files.where('type = ?', 'Image')
end

#pdfsObject



53
54
55
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 53

def pdfs
  self.files.where('type = ?', 'Pdf')
end

#stylesheetsObject



49
50
51
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 49

def stylesheets
  self.files.where('type = ?', 'Stylesheet')
end

#templatesObject



45
46
47
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 45

def templates
						self.files.where('type = ?', 'Template')
end

#xmlsObject



57
58
59
# File 'lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb', line 57

def xmls
  self.files.where('type = ?', 'XmlFile')
end