Class: Churned::Commands::DB::Load

Inherits:
Churned::Command show all
Defined in:
lib/churned/commands/db/load.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Churned::Command

#command, #cursor, #db, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ Load

Returns a new instance of Load.



9
10
11
# File 'lib/churned/commands/db/load.rb', line 9

def initialize(options)
  @options = options
end

Class Method Details

.execute(filename) ⇒ Object



13
14
15
# File 'lib/churned/commands/db/load.rb', line 13

def self.execute(filename)
  new({}).execute(filename, input: $stdin, output: $stdout)
end

Instance Method Details

#execute(filename, input: $stdin, output: $stdout) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/churned/commands/db/load.rb', line 17

def execute(filename, input: $stdin, output: $stdout)
  IO.read(filename).split("\n\n").each do |description|
    sha, date, author, *numstats = description.split("\n")

    commit = Commit.new(sha: sha, author_date: date, author: author)

    numstats.each do |numstat|
      additions, deletions, pathname = numstat.split("\t")
      commit.file_changes.build(additions: additions, deletions: deletions, pathname: pathname)
    end

    commit.save
  end
end