Module: Card::Set::All::Utils::ClassMethods
- Defined in:
- tmpsets/set/mod001-01_core/all/utils.rb
Instance Method Summary collapse
-
#delete_trashed_files ⇒ Object
deletes any file not associated with a real card.
- #empty_trash ⇒ Object
- #merge(name, attribs = {}, opts = {}) ⇒ Object
- #merge_list(attribs, opts = {}) ⇒ Object
Instance Method Details
#delete_trashed_files ⇒ Object
deletes any file not associated with a real card.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'tmpsets/set/mod001-01_core/all/utils.rb', line 14 def delete_trashed_files #deletes any file not associated with a real card. dir = Card.paths['files'].existent.first trashed_card_sql = %{ select id from cards where trash is true } trashed_card_ids = Card.connection.select_all( trashed_card_sql ).map( &:values ).flatten.map &:to_i file_ids = Dir.entries( dir )[2..-1].map( &:to_i ) file_ids.each do |file_id| if trashed_card_ids.member?(file_id) raise Card::Error, "Narrowly averted deleting current file" if Card.exists?(file_id) #double check! FileUtils.rm_rf "#{dir}/#{file_id}", :secure => true end end end |
#empty_trash ⇒ Object
6 7 8 9 10 11 12 |
# File 'tmpsets/set/mod001-01_core/all/utils.rb', line 6 def empty_trash Card.delete_trashed_files Card.where(:trash=>true).delete_all Card::Action.delete_cardless Card::Reference.repair_missing_referees Card::Reference.delete_missing_referers end |
#merge(name, attribs = {}, opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'tmpsets/set/mod001-01_core/all/utils.rb', line 55 def merge name, attribs={}, opts={} puts "merging #{ name }" card = fetch name, :new=>{} if opts[:pristine] && !card.pristine? false else card.attributes = attribs card.save! end end |
#merge_list(attribs, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'tmpsets/set/mod001-01_core/all/utils.rb', line 27 def merge_list attribs, opts={} unmerged = [] attribs.each do |row| result = begin merge row['name'], row, opts # rescue => e # Rails.logger.info "merge_list problem: #{ e.message }" # false end unmerged.push row unless result == true end if unmerged.empty? Rails.logger.info "successfully merged all!" else unmerged_json = JSON.pretty_generate unmerged if output_file = opts[:output_file] ::File.open output_file, 'w' do |f| f.write unmerged_json end else Rails.logger.info "failed to merge:\n\n#{ unmerged_json }" end end unmerged end |