Class: GitObjectBrowser::Dumper::RefsDumper
- Inherits:
-
Object
- Object
- GitObjectBrowser::Dumper::RefsDumper
- Defined in:
- lib/git-object-browser/dumper/refs_dumper.rb
Instance Method Summary collapse
- #dump ⇒ Object
- #dump_object(input, output, path) ⇒ Object
-
#initialize(root, outdir) ⇒ RefsDumper
constructor
A new instance of RefsDumper.
Constructor Details
#initialize(root, outdir) ⇒ RefsDumper
Returns a new instance of RefsDumper.
9 10 11 12 |
# File 'lib/git-object-browser/dumper/refs_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/refs_dumper.rb', line 14 def dump ref_files = %w{HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD CHERRY_PICK_HEAD} Dir.chdir(@root) do Dir.glob("refs/**/*") do |path| ref_files << path if File.file?(path) end end return if ref_files.empty? ref_files.each do |path| next unless File.exist?(File.join(@root, path)) outfile = File.join(@outdir, "#{ path }.json") FileUtils.mkdir_p(File.dirname(outfile)) puts "Write: #{path}\n" ref_file = File.join(@root, path) File.open(ref_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/refs_dumper.rb', line 38 def dump_object(input, output, path) obj = GitObjectBrowser::Models::Ref.new(input) wrapped = GitObjectBrowser::Models::WrappedObject.new(nil, path, obj) output << JSON.pretty_generate(wrapped.to_hash) end |