Class: GitObjectBrowser::Dumper::ReflogDumper
- Inherits:
-
Object
- Object
- GitObjectBrowser::Dumper::ReflogDumper
- Defined in:
- lib/git-object-browser/dumper/reflog_dumper.rb
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_object(input, output, path) ⇒ Object
-
#initialize(root, outdir) ⇒ ReflogDumper
constructor
A new instance of ReflogDumper.
Constructor Details
#initialize(root, outdir) ⇒ ReflogDumper
Returns a new instance of ReflogDumper.
9 10 11 12 |
# File 'lib/git-object-browser/dumper/reflog_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 |
# File 'lib/git-object-browser/dumper/reflog_dumper.rb', line 14 def dump files = [] Dir.chdir(@root) do Dir.glob("logs/**/*") do |path| files << path if File.file?(path) end end return if files.empty? files.each do |path| file = File.join(@root, path) next unless File.exist?(file) outfile = File.join(@outdir, "#{ path }.json") FileUtils.mkdir_p(File.dirname(outfile)) puts "Write: #{path}\n" 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
38 39 40 41 42 |
# File 'lib/git-object-browser/dumper/reflog_dumper.rb', line 38 def dump_object(input, output, path) obj = GitObjectBrowser::Models::Reflog.new(input).parse wrapped = GitObjectBrowser::Models::WrappedObject.new(nil, path, obj) output << JSON.pretty_generate(wrapped.to_hash) end |