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
-
#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 |
# File 'lib/relaxo/database.rb', line 31 def initialize(path, branch, = {}) @path = path @metadata = @repository = Rugged::Repository.new(path) @branch = branch end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
45 46 47 |
# File 'lib/relaxo/database.rb', line 45 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
44 45 46 |
# File 'lib/relaxo/database.rb', line 44 def path @path end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
46 47 48 |
# File 'lib/relaxo/database.rb', line 46 def repository @repository end |
Instance Method Details
#[](key) ⇒ Object
59 60 61 |
# File 'lib/relaxo/database.rb', line 59 def [] key @metadata[key] end |
#clear! ⇒ Object
Completely clear out the database.
49 50 51 52 53 |
# File 'lib/relaxo/database.rb', line 49 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/relaxo/database.rb', line 65 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
40 41 42 |
# File 'lib/relaxo/database.rb', line 40 def config @repository.config end |
#current {|dataset| ... } ⇒ Object
Efficient point-in-time read-only access.
84 85 86 87 88 89 90 91 92 |
# File 'lib/relaxo/database.rb', line 84 def current _, tree = latest_commit dataset = Dataset.new(@repository, tree) yield dataset if block_given? return dataset end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/relaxo/database.rb', line 55 def empty? @repository.empty? end |
#history(path) ⇒ Object
revision history of given object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/relaxo/database.rb', line 95 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 |