Class: Gifts::FileTable
Constant Summary
collapse
- TypeText =
1
- TypeBinary =
2
Instance Method Summary
collapse
Methods inherited from TableBase
#initialize
Instance Method Details
#add(git_commit, git_diff, db_commit) ⇒ Object
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
|
# File 'lib/gifts/file_table.rb', line 23
def add(git_commit, git_diff, db_commit)
path = git_diff.new_path
file = (git_commit.tree / path)
if file.nil? && git_commit.parents.count > 0
path = git_diff.old_path
file = (git_commit.parents.first.tree / path)
end
return if file.nil?
key = db_commit.repo.id.to_s + ":" + path
return table[key] if table[key] && table[key].last_commit.committed_date > db_commit.committed_date
ext = File.extname(path).sub(".", "")
t = table[key] || table.add(key, repo: db_commit.repo, path: path, ext: ext)
t.last_commit = db_commit
detection = CharlockHolmes::EncodingDetector.detect(file.data)
if detection[:type] == :binary
t.type = TypeBinary
else
t.type = TypeText
t.encoding = detection[:encoding]
end
t
end
|
#define_schema ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/gifts/file_table.rb', line 10
def define_schema
Groonga::Schema.define do |schema|
schema.create_table(table_name, type: :hash) do |table|
table.string("encoding")
table.string("ext")
table.reference("last_commit", "commit")
table.string("path")
table.reference("repo")
table.int32("type")
end
end
end
|
#table_name ⇒ Object
6
7
8
|
# File 'lib/gifts/file_table.rb', line 6
def table_name
"file"
end
|