Class: GitObjectBrowser::Dumper::ObjectsDumper
- Inherits:
-
Object
- Object
- GitObjectBrowser::Dumper::ObjectsDumper
- Defined in:
- lib/git-object-browser/dumper/objects_dumper.rb
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_object(input, output, path) ⇒ Object
-
#initialize(root, outdir) ⇒ ObjectsDumper
constructor
A new instance of ObjectsDumper.
Constructor Details
#initialize(root, outdir) ⇒ ObjectsDumper
Returns a new instance of ObjectsDumper.
9 10 11 12 |
# File 'lib/git-object-browser/dumper/objects_dumper.rb', line 9 def initialize(root, outdir) @root = root @outdir = outdir end |
Instance Method Details
#dump ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git-object-browser/dumper/objects_dumper.rb', line 14 def dump obj_files = [] Dir.chdir(@root) do Dir.glob("objects/**/*") do |path| obj_files << path if File.file?(path) && path =~ %r{/[a-z0-9]{38}$} end end return if obj_files.empty? obj_files.each do |path| outfile = File.join(@outdir, "#{ path }.json") next if File.exist?(outfile) FileUtils.mkdir_p(File.dirname(outfile)) puts "Write: #{path}\n" obj_file = File.join(@root, path) File.open(obj_file) do |input| File.open(outfile, "w") do |output| dump_object(input, output, path) end end end end |
#dump_object(input, output, path) ⇒ Object
39 40 41 42 43 |
# File 'lib/git-object-browser/dumper/objects_dumper.rb', line 39 def dump_object(input, output, path) obj = GitObjectBrowser::Models::GitObject.new(input).parse wrapped = GitObjectBrowser::Models::WrappedObject.new(nil, path, obj) output << JSON.pretty_generate(wrapped.to_hash) end |