Class: Relaxo::Changeset
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Dataset
#directory?, #each, #exist?, #file?
Constructor Details
#initialize(repository, tree) ⇒ Changeset
Returns a new instance of Changeset.
25
26
27
28
29
30
|
# File 'lib/relaxo/changeset.rb', line 25
def initialize(repository, tree)
super
@changes = {}
@directories = {}
end
|
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
33
34
35
|
# File 'lib/relaxo/changeset.rb', line 33
def changes
@changes
end
|
#ref ⇒ Object
Returns the value of attribute ref.
32
33
34
|
# File 'lib/relaxo/changeset.rb', line 32
def ref
@ref
end
|
Instance Method Details
#abort! ⇒ Object
90
91
92
|
# File 'lib/relaxo/changeset.rb', line 90
def abort!
throw :abort
end
|
#append(data, type = :blob) ⇒ Object
49
50
51
52
53
|
# File 'lib/relaxo/changeset.rb', line 49
def append(data, type = :blob)
oid = @repository.write(data, type)
return @repository.read(oid)
end
|
#changes? ⇒ Boolean
35
36
37
|
# File 'lib/relaxo/changeset.rb', line 35
def changes?
@changes.any?
end
|
#delete(path) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/relaxo/changeset.rb', line 75
def delete(path)
root, _, name = path.rpartition('/')
entry = @changes[path] = {
action: :remove,
path: path,
root: root,
name: name,
}
fetch_directory(root).delete(entry)
return entry
end
|
#read(path) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/relaxo/changeset.rb', line 39
def read(path)
if update = @changes[path]
if update[:action] != :remove
@repository.read(update[:oid])
end
else
super
end
end
|
#write(path, object, mode = 0100644) ⇒ Object
Also known as:
[]=
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/relaxo/changeset.rb', line 55
def write(path, object, mode = 0100644)
root, _, name = path.rpartition('/')
entry = @changes[path] = {
action: :upsert,
oid: object.oid,
object: object,
filemode: mode,
path: path,
root: root,
name: name,
}
fetch_directory(root).insert(entry)
return entry
end
|
#write_tree ⇒ Object
94
95
96
|
# File 'lib/relaxo/changeset.rb', line 94
def write_tree
@tree.update(@changes.values)
end
|