Module: Card::Set::All::Utils::ClassMethods
- Defined in:
- tmpsets/set/mod002-core/all/utils.rb
Overview
~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/core/set/all/utils.rb ~~
Instance Method Summary collapse
- #delete_tmp_files(id = nil) ⇒ Object
- #merge(name, attribs = {}, opts = {}) ⇒ Object
- #merge_list(attribs, opts = {}) ⇒ Object
- #report_unmerged_json(unmerged_json, output_file) ⇒ Object
- #seed_test_db ⇒ Object
Instance Method Details
#delete_tmp_files(id = nil) ⇒ Object
5 6 7 8 9 10 11 |
# File 'tmpsets/set/mod002-core/all/utils.rb', line 5 def delete_tmp_files id=nil dir = Cardio.paths["files"].existent.first + "/tmp" dir += "/#{id}" if id FileUtils.rm_rf dir, secure: true rescue Rails.logger.info "failed to remove tmp files" end |
#merge(name, attribs = {}, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'tmpsets/set/mod002-core/all/utils.rb', line 41 def merge name, attribs={}, opts={} puts "merging #{name}" card = fetch name, new: {} [:image, :file].each do |attach| next unless attribs[attach] && attribs[attach].is_a?(String) attribs[attach] = ::File.open(attribs[attach]) end if opts[:pristine] && !card.pristine? false else card.update_attributes! attribs end end |
#merge_list(attribs, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'tmpsets/set/mod002-core/all/utils.rb', line 13 def merge_list attribs, opts={} unmerged = [] attribs.each do |row| result = begin merge row["name"], row, opts end unmerged.push row unless result == true end if unmerged.empty? Rails.logger.info "successfully merged all!" else unmerged_json = JSON.pretty_generate unmerged report_unmerged_json unmerged_json, opts[:output_file] end unmerged end |
#report_unmerged_json(unmerged_json, output_file) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'tmpsets/set/mod002-core/all/utils.rb', line 31 def report_unmerged_json unmerged_json, output_file if 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 |
#seed_test_db ⇒ Object
55 56 57 |
# File 'tmpsets/set/mod002-core/all/utils.rb', line 55 def seed_test_db system "env RAILS_ENV=test bundle exec rake db:fixtures:load" end |