Class: Ditto::Runner
- Inherits:
-
Object
- Object
- Ditto::Runner
- Defined in:
- lib/ditto/runner.rb
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
-
#load_files(list, type = nil) ⇒ Object
Load any filetype depending on it’s extension.
- #run ⇒ Object
-
#store_data ⇒ Object
Add the data to the database.
Constructor Details
Instance Method Details
#load_files(list, type = nil) ⇒ Object
Load any filetype depending on it’s extension
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ditto/runner.rb', line 36 def load_files list, type = nil nfiles = 0 nerr = 0 list.each do |f| ext = File.extname(f) next if type and ext != type puts "loading #{f}" if @opts.verbose > 0 nfiles += 1 case ext when '.yaml' nent = Entity.load_instances f, @opts.verbose puts "#{nent} instances loaded" if @opts.verbose > 0 when '.ditto' Ditto::Entity.load_from_file f when '.dm' begin load File.absolute_path(f) rescue ScriptError, StandardError => le loc = le.backtrace[2].split(':') puts "Error: #{le.to_s} (line #{loc[1]} in #{loc[0]})" end end end puts "#{nfiles} files loaded" if @opts.verbose > 0 end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ditto/runner.rb', line 11 def run begin if @opts.check puts "Checking..." if @opts.verbose > 0 load_files @opts.loadfiles exit end load_files @opts.loadfiles, '.yaml' raise "dittomart file must be specified!" unless @opts.dittomart puts "dittomart file: #{@opts.dittomart}" if @opts.verbose > 0 load_files @opts.martfiles, '.dm' Ditto::Entity.load_entities @opts.entitydir, @opts.verbose store_data return 0 rescue Ditto::Error => de STDERR.puts de.(@opts.debug) rescue StandardError => e STDERR.puts "\n#{e.class}: #{e.}" STDERR.puts e.backtrace if @opts.debug end return 99 end |
#store_data ⇒ Object
Add the data to the database
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ditto/runner.rb', line 64 def store_data puts "Running against: #{@opts.connstring}" if @opts.verbose > 0 DataMapper::Logger.new(STDOUT, (@opts.verbose > 1) ? :debug : :info) DataMapper.setup(:default, @opts.connstring) DataMapper.finalize begin if @opts.droptables DataMapper.auto_migrate! else DataMapper.auto_upgrade! end return Ditto::Entity.store_all @opts.verbose rescue StandardError => e STDERR.puts "\nERROR: #{e.to_s}" STDERR.puts e.backtrace if @opts.debug return false end end |