Class: Relaxo::Database
- Inherits:
-
Object
- Object
- Relaxo::Database
- Defined in:
- lib/relaxo/database.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#clear! ⇒ Object
Completely clear out the database.
-
#commit(**options) ⇒ Object
During the execution of the block, changes don’t get stored immediately, so reading from the dataset (from outside the block) will continue to return the values that were stored in the configuration when the transaction was started.
- #config ⇒ Object
-
#current {|dataset| ... } ⇒ Object
Efficient point-in-time read-only access.
- #empty? ⇒ Boolean
- #head ⇒ Object
-
#history(path) ⇒ Object
revision history of given object.
-
#initialize(path, branch, metadata = {}) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(path, branch, metadata = {}) ⇒ Database
Returns a new instance of Database.
17 18 19 20 21 22 23 24 25 |
# File 'lib/relaxo/database.rb', line 17 def initialize(path, branch, = {}) @path = path @metadata = @repository = Rugged::Repository.new(path) # @repository.config['core.fsyncObjectFiles'] = fsync @branch = branch end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
32 33 34 |
# File 'lib/relaxo/database.rb', line 32 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
31 32 33 |
# File 'lib/relaxo/database.rb', line 31 def path @path end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
33 34 35 |
# File 'lib/relaxo/database.rb', line 33 def repository @repository end |
Instance Method Details
#[](key) ⇒ Object
50 51 52 |
# File 'lib/relaxo/database.rb', line 50 def [] key @metadata[key] end |
#clear! ⇒ Object
Completely clear out the database.
36 37 38 39 40 |
# File 'lib/relaxo/database.rb', line 36 def clear! if head = @repository.branches[@branch] @repository.references.delete(head) end end |
#commit(**options) ⇒ Object
During the execution of the block, changes don’t get stored immediately, so reading from the dataset (from outside the block) will continue to return the values that were stored in the configuration when the transaction was started.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/relaxo/database.rb', line 56 def commit(**) result = nil track_time([:message]) do catch(:abort) do begin parent, tree = latest_commit changeset = Changeset.new(@repository, tree) result = yield changeset end until apply(parent, changeset, **) end end return result end |
#config ⇒ Object
27 28 29 |
# File 'lib/relaxo/database.rb', line 27 def config @repository.config end |
#current {|dataset| ... } ⇒ Object
Efficient point-in-time read-only access.
75 76 77 78 79 80 81 82 83 |
# File 'lib/relaxo/database.rb', line 75 def current _, tree = latest_commit dataset = Dataset.new(@repository, tree) yield dataset if block_given? return dataset end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/relaxo/database.rb', line 42 def empty? @repository.empty? end |
#head ⇒ Object
46 47 48 |
# File 'lib/relaxo/database.rb', line 46 def head @repository.branches[@branch] end |
#history(path) ⇒ Object
revision history of given object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/relaxo/database.rb', line 86 def history(path) head, _ = latest_commit walker = Rugged::Walker.new(@repository) # Sounds like 'Walker, Texas Ranger'... walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) walker.push(head.oid) commits = [] old_oid = nil walker.each do |commit| dataset = Dataset.new(@repository, commit.tree) oid = dataset.read(path).oid if oid != old_oid # modified yield commit if block_given? commits << commit old_oid = oid end break if oid.nil? && !old_oid.nil? # deleted or moved end return commits end |