Class: GitObjectBrowser::Dumper::PlainFilesDumper
- Inherits:
-
Object
- Object
- GitObjectBrowser::Dumper::PlainFilesDumper
- Defined in:
- lib/git-object-browser/dumper/plain_files_dumper.rb
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_object(input, output, path) ⇒ Object
-
#initialize(root, outdir) ⇒ PlainFilesDumper
constructor
A new instance of PlainFilesDumper.
Constructor Details
#initialize(root, outdir) ⇒ PlainFilesDumper
Returns a new instance of PlainFilesDumper.
9 10 11 12 |
# File 'lib/git-object-browser/dumper/plain_files_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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/git-object-browser/dumper/plain_files_dumper.rb', line 14 def dump obj_files = [] # ! info/refs # info # logs # objects/info plain_files = [] subdirs = [] Dir.chdir(@root) do Dir.glob('*') do |path| next if %w{HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD CHERRY_PICK_HEAD}.include?(path) next if %w{dump index objects refs packed-refs logs}.include?(path) if File.directory?(path) subdirs << path else plain_files << path end end end subdirs << 'objects/info' subdirs.each do |dir| next unless File.directory?(File.join(@root, dir)) Dir.chdir(File.join(@root, dir)) do Dir.glob('**/*') do |path| # skip info/refs (InfoRefs) next if dir == 'info' && path == 'refs' if File.file?(path) plain_files << File.join(dir, path) end end end end plain_files.each do |path| outfile = File.join(@outdir, "#{ path }.json") FileUtils.mkdir_p(File.dirname(outfile)) puts "Write: #{path}\n" file = File.join(@root, path) File.open(file) do |input| File.open(outfile, "w") do |output| dump_object(input, output, path) end end end end |
#dump_object(input, output, path) ⇒ Object
66 67 68 69 70 |
# File 'lib/git-object-browser/dumper/plain_files_dumper.rb', line 66 def dump_object(input, output, path) obj = GitObjectBrowser::Models::PlainFile.new(input).parse wrapped = GitObjectBrowser::Models::WrappedObject.new(nil, path, obj) output << JSON.pretty_generate(wrapped.to_hash) end |