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.
10
11
12
13
14
15
|
# File 'lib/relaxo/changeset.rb', line 10
def initialize(repository, tree)
super
@changes = {}
@directories = {}
end
|
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
18
19
20
|
# File 'lib/relaxo/changeset.rb', line 18
def changes
@changes
end
|
#ref ⇒ Object
Returns the value of attribute ref.
17
18
19
|
# File 'lib/relaxo/changeset.rb', line 17
def ref
@ref
end
|
Instance Method Details
#abort! ⇒ Object
75
76
77
|
# File 'lib/relaxo/changeset.rb', line 75
def abort!
throw :abort
end
|
#append(data, type = :blob) ⇒ Object
34
35
36
37
38
|
# File 'lib/relaxo/changeset.rb', line 34
def append(data, type = :blob)
oid = @repository.write(data, type)
return @repository.read(oid)
end
|
#changes? ⇒ Boolean
20
21
22
|
# File 'lib/relaxo/changeset.rb', line 20
def changes?
@changes.any?
end
|
#delete(path) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/relaxo/changeset.rb', line 60
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
24
25
26
27
28
29
30
31
32
|
# File 'lib/relaxo/changeset.rb', line 24
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:
[]=
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/relaxo/changeset.rb', line 40
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
79
80
81
|
# File 'lib/relaxo/changeset.rb', line 79
def write_tree
@tree.update(@changes.values)
end
|