Module: Qcontent::Assets::InstanceMethods

Defined in:
lib/qcontent/assets.rb

Instance Method Summary collapse

Instance Method Details

#collect_assets_to_save(group, hash_of_assets) ⇒ Object



44
45
46
47
48
# File 'lib/qcontent/assets.rb', line 44

def collect_assets_to_save(group, hash_of_assets)
  return unless hash_of_assets
  @assets_to_save ||= {}
  @assets_to_save[group.to_s] = hash_of_assets
end

#save_assetsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/qcontent/assets.rb', line 50

def save_assets
  logger.debug '== Saving Assets'
  return unless @assets_to_save
  @assets_to_save.each do |group_name, asset_group|
    logger.debug '--- Deleting the whole group'
    self.send("content_#{group_name}").delete_all
    logger.debug "--- Saving Asset group #{group_name} on #{self}"
    asset_group.each do |position, asset_attributes|
      logger.debug "---- #{position}: #{asset_attributes.inspect}"
      if asset_attributes.is_a?(Hash)
        asset = Asset.create({:dir => group_name.to_s}.merge(asset_attributes))
        self.content_assets.create(:asset_id => asset.id, :position => position, :asset_group => group_name.to_s) if asset
      elsif asset_attributes.to_i > 0
        self.content_assets.create(:asset_id => asset_attributes.to_i, :position => position, :asset_group => group_name.to_s)
      end
    end
  end
end