Class: Gglog::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/gglog/database.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open(base_path, encoding, &blk) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/gglog/database.rb', line 7

def open(base_path, encoding, &blk)
  if blk
    Database.new.open(base_path, encoding, &blk)
  else
    Database.new.open(base_path, encoding)
  end
end

Instance Method Details

#add_commit_message(commit_message) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/gglog/database.rb', line 58

def add_commit_message(commit_message)
  Groonga["commit_messages"].add(
    first_line: commit_message.first_line,
    body: commit_message.body,
    repository: commit_message.repository,
    sha: commit_message.sha
  )
end

#closeObject



32
33
34
# File 'lib/gglog/database.rb', line 32

def close
  close_groonga_db
end

#initilizeObject



16
17
18
# File 'lib/gglog/database.rb', line 16

def initilize
  @database = nil
end

#open(base_path, encoding) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gglog/database.rb', line 20

def open(base_path, encoding)
  reset_groonga_context(encoding)
  open_groonga_db(base_path)
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
end

#recreateObject



53
54
55
56
# File 'lib/gglog/database.rb', line 53

def recreate
  remove_tables
  create_tables
end

#search(words) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gglog/database.rb', line 36

def search(words)
  records_selected = Groonga["commit_messages"].select do |record|
    conditions = [record.first_line =~ words]
  end
  records = records_selected.sort([
    { key: "_score", order: 'descending' },
    { key: "repository", order: 'ascending' },
    { key: "first_line", order: 'ascending' }
  ])
  # convert to Array from Groonga::Array to keep before 2.1.0 style
  #  see http://ranguba.org/rroonga/ja/Groonga/Table.html#sort-instance_method
  records = records.collect {|record| record.value }

  filtered_records = filter_records(records)
  convert_records_to_commit_messages(filtered_records)
end