Class: Gifts::Database

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ Database

Returns a new instance of Database.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gifts/database.rb', line 26

def initialize(database)
  @database = database

  # Tables need initialized in the order corresponding to referenced.
  @repos = RepoTable.new(self)
  @users = UserTable.new(self)
  @commits = CommitTable.new(self)
  @files = FileTable.new(self)
  @diffs = DiffTable.new(self)
  @terms = TermTable.new(self)
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



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

def commits
  @commits
end

#diffsObject (readonly)

Returns the value of attribute diffs.



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

def diffs
  @diffs
end

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

#reposObject (readonly)

Returns the value of attribute repos.



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

def repos
  @repos
end

#termsObject (readonly)

Returns the value of attribute terms.



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

def terms
  @terms
end

#usersObject (readonly)

Returns the value of attribute users.



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

def users
  @users
end

Class Method Details

.open(filename) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gifts/database.rb', line 5

def self.open(filename)
  if File.exist?(filename)
    database = Groonga::Database.open(filename)
  else
    FileUtils.mkdir_p(File.dirname filename)
    database = Groonga::Database.create(path: filename)
  end

  database = Database.new(database)

  if block_given?
    begin
      yield database
    ensure
      database.close
    end
  else
    database
  end
end

Instance Method Details

#closeObject



38
39
40
41
42
43
# File 'lib/gifts/database.rb', line 38

def close
  unless closed?
    @database.close
    @database = nil
  end
end

#closed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gifts/database.rb', line 45

def closed?
  @database.nil? or @database.closed?
end