Class: Dflat::Version::Full
- Inherits:
-
Dir
- Object
- Dir
- Dir
- Dflat::Version::Full
show all
- Defined in:
- lib/dflat/version.rb
Constant Summary
collapse
- DATA_DIR =
'full'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Dir
load, #manifest, #manifest!, #version
Class Method Details
.mkdir(path, integer = 0777, args = {}) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/dflat/version.rb', line 49
def self.mkdir path, integer = 0777, args = {}
super path, integer
d = Full.new path
Dnatural::Dir.mkdir File.join(d.path, DATA_DIR)
d
end
|
Instance Method Details
#add(src, dest, options = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/dflat/version.rb', line 60
def add src, dest, options = {}
file = FileUtils.cp src, File.join(data_path, dest), options
manifest!
lock
m = manifest.add dest, :base => data_path
File.open(File.join(path, 'manifest.txt'), 'w') do |f|
f.write(m.to_s)
end
unlock
File.new File.join(data_path, dest)
end
|
#list ⇒ Object
56
57
58
|
# File 'lib/dflat/version.rb', line 56
def list
manifest.entries.map { |e| e.sourcefileorurl }
end
|
#remove(list, options = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/dflat/version.rb', line 74
def remove list, options = {}
list = [list] if list.instance_of? String
FileUtils.rm list.map { |x| File.join(data_path, x) }, options
m = manifest!
lock
list.each do |l|
m = m.remove l
end
File.open(File.join(path, 'manifest.txt'), 'w') do |f|
f.write(m.to_s)
end
unlock
end
|
#to_delta(version) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/dflat/version.rb', line 90
def to_delta version
redd = ReDD::Dir.mkdir File.join(self.path, Delta::DATA_DIR)
delta = Delta.new self.path
old = self.manifest.to_hash
new = version.manifest.to_hash
changeset = {:delete => [], :add => []}
new.select do |filename, entry|
changeset[:delete] << filename unless old[filename] and old[filename] == entry[filename]
end
old.select do |filename, entry|
changeset[:add] << filename unless new[filename] and old[filename] == entry[filename]
end
changeset[:delete].each do |filename|
delta.remove filename
end
changeset[:add].each do |filename|
delta.add File.join(data_path, filename), filename
end
FileUtils.rm_rf data_path
return delta
end
|