Module: MetaRecordRunner
- Included in:
- Guard::MetaRecord
- Defined in:
- lib/metarecord/runner.rb
Instance Method Summary collapse
Instance Method Details
#manifest_path ⇒ Object
5 6 7 |
# File 'lib/metarecord/runner.rb', line 5 def manifest_path ".metarecord-manifest.json" end |
#run_all ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/metarecord/runner.rb', line 9 def run_all @generators.each do |generator| require "metarecord/generators/#{generator.to_s}_generator" end `rm -Rf #{@tmpdir} && mkdir -p #{@tmpdir}` GeneratorBase.prepare @input, @tmpdir, @base_path GeneratorBase.odb_connection = @odb_connection || { object: "Crails::Odb::Connection", include: "crails/odb/connection.hpp" } ManifestGenerator.new.generate "#{@tmpdir}/#{manifest_path}" @old_manifest = JSON.parse File.read(manifest_path) rescue {} @new_manifest = JSON.parse File.read("#{@tmpdir}/#{manifest_path}") @generators.each do |generator| const_name = generator.to_s.camelcase + "Generator" klass = Kernel.const_get const_name GeneratorBase.use klass if klass.new.should_generate_from_manifest klass.new.generate_manifest @old_manifest, @new_manifest end end update_files end |
#update_files ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/metarecord/runner.rb', line 30 def update_files `cp "#{@tmpdir}/#{manifest_path}" "#{manifest_path}"` Dir["#{@tmpdir}/**/*"].each do |tmp_file| next if File.directory? tmp_file new_path = "#{@output}/#{tmp_file[@tmpdir.size + 1..tmp_file.size]}" if (not File.exists?(new_path)) || File.read(new_path) != File.read(tmp_file) puts "[metarecord] generated #{new_path}" `mkdir -p '#{File.dirname new_path}'` `cp '#{tmp_file}' '#{new_path}'` elsif @verbose == true puts "[metarecord] no updates required for #{new_path}" end end @input.each do |input| Dir["#{@output}/#{input}/**/*"].each do |actual_file| next if File.directory? actual_file tmp_path = "#{@tmpdir}/#{@output[@output.size + 1..@output.size]}" if not File.exists?(tmp_path) puts "[metarecord] removed #{actual_file}" `rm '#{actual_file}'` end end end end |