Class: Gifts::DiffTable

Inherits:
TableBase show all
Defined in:
lib/gifts/diff_table.rb

Instance Method Summary collapse

Methods inherited from TableBase

#initialize

Constructor Details

This class inherits a constructor from Gifts::TableBase

Instance Method Details

#add(git_commit, db_commit) ⇒ Object



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
# File 'lib/gifts/diff_table.rb', line 17

def add(git_commit, db_commit)
  if db_commit.status == CommitTable::StatusProcessing
    result = []

    begin
      git_commit.diffs.each do |git_diff|
        next if git_diff.diff.nil?

        db_file = @db.files.add(git_commit, git_diff, db_commit)

        if db_file && db_file.type == FileTable::TypeText
          key = db_commit.id.to_s + ":" + db_file.id.to_s
          db_diff =
            table[key] ||
            table.add(
              key,
              commit: db_commit,
              file: db_file,
              diff: git_diff.diff
            )
          result << db_diff
        end
      end
    rescue Grit::Git::GitTimeout => e
      puts "Timeout commit:#{git_commit.id}"
      db_commit.status = CommitTable::StatusTimeout
    else
      db_commit.status = CommitTable::StatusCompleted
    end

    result
  else
    records = table.select do |record|
      record.commit == db_commit
    end
  end
end

#define_schemaObject



7
8
9
10
11
12
13
14
15
# File 'lib/gifts/diff_table.rb', line 7

def define_schema
  Groonga::Schema.define do |schema|
    schema.create_table(table_name, type: :hash) do |table|
      table.reference("commit")
      table.reference("file")
      table.text("diff")
    end
  end
end

#table_nameObject



3
4
5
# File 'lib/gifts/diff_table.rb', line 3

def table_name
  "diff"
end