Class: Gifts::Database
- Inherits:
-
Object
- Object
- Gifts::Database
- Defined in:
- lib/gifts/database.rb
Instance Attribute Summary collapse
-
#commits ⇒ Object
readonly
Returns the value of attribute commits.
-
#diffs ⇒ Object
readonly
Returns the value of attribute diffs.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#repos ⇒ Object
readonly
Returns the value of attribute repos.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(database) ⇒ Database
constructor
A new instance of Database.
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
#commits ⇒ Object (readonly)
Returns the value of attribute commits.
3 4 5 |
# File 'lib/gifts/database.rb', line 3 def commits @commits end |
#diffs ⇒ Object (readonly)
Returns the value of attribute diffs.
3 4 5 |
# File 'lib/gifts/database.rb', line 3 def diffs @diffs end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/gifts/database.rb', line 3 def files @files end |
#repos ⇒ Object (readonly)
Returns the value of attribute repos.
3 4 5 |
# File 'lib/gifts/database.rb', line 3 def repos @repos end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
3 4 5 |
# File 'lib/gifts/database.rb', line 3 def terms @terms end |
#users ⇒ Object (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
#close ⇒ Object
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
45 46 47 |
# File 'lib/gifts/database.rb', line 45 def closed? @database.nil? or @database.closed? end |