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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/relaxo/database.rb', line 31 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.
46 47 48 |
# File 'lib/relaxo/database.rb', line 46 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
45 46 47 |
# File 'lib/relaxo/database.rb', line 45 def path @path end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
47 48 49 |
# File 'lib/relaxo/database.rb', line 47 def repository @repository end |
Instance Method Details
#[](key) ⇒ Object
64 65 66 |
# File 'lib/relaxo/database.rb', line 64 def [] key @metadata[key] end |
#clear! ⇒ Object
Completely clear out the database.
50 51 52 53 54 |
# File 'lib/relaxo/database.rb', line 50 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/relaxo/database.rb', line 70 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
41 42 43 |
# File 'lib/relaxo/database.rb', line 41 def config @repository.config end |
#current {|dataset| ... } ⇒ Object
Efficient point-in-time read-only access.
89 90 91 92 93 94 95 96 97 |
# File 'lib/relaxo/database.rb', line 89 def current _, tree = latest_commit dataset = Dataset.new(@repository, tree) yield dataset if block_given? return dataset end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/relaxo/database.rb', line 56 def empty? @repository.empty? end |
#head ⇒ Object
60 61 62 |
# File 'lib/relaxo/database.rb', line 60 def head @repository.branches[@branch] end |
#history(path) ⇒ Object
revision history of given object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/relaxo/database.rb', line 100 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 |