Class: URI::File
Constant Summary
collapse
- COMPONENT =
[
:scheme,
:path
].freeze
- @@tar =
'tar'.to_cmd.freeze
- @@gzip =
'gzip'.to_cmd.freeze
Instance Method Summary
collapse
Methods inherited from Generic
#add_query, #mk_custom_opts, #pathname, #pathname=, #to_uri, #to_yaml_string, yaml_load
Constructor Details
#initialize(*args) ⇒ File
Returns a new instance of File.
24
25
26
27
28
29
30
|
# File 'lib/uri/file.rb', line 24
def initialize ( *args )
super
unless @host.nil? or @host.empty?
raise ArgumentError,
"You cannot neither setup a host (#{@host}), nor a relative path"
end
end
|
Instance Method Details
32
33
34
35
36
|
# File 'lib/uri/file.rb', line 32
def checkout
p = pathname
raise CheckoutError, to_s unless p.exist?
[p, nil]
end
|
#commit(aPath) ⇒ Object
38
39
40
|
# File 'lib/uri/file.rb', line 38
def commit ( aPath )
aPath.cp_r(self.pathname)
end
|
#fingerprint ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/uri/file.rb', line 56
def fingerprint
digest = Digest::MD5.new
if pathname.directory?
pathname.find do |path|
next if path.directory?
digest << path.read
end
else
digest << pathname.read
end
digest.to_s
end
|
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/uri/file.rb', line 42
def save
p = pathname
raise SaveError, to_s unless p.exist?
if p.directory?
out = TempPath.new('save', "#{p.basename}.tar.gz")
cmd = tar['czf', out, p]
else
out = TempPath.new('save', "#{p.basename}.gz")
cmd = gzip['-c', p] > out
end
cmd.run(runner)
[out, nil]
end
|
69
70
71
|
# File 'lib/uri/file.rb', line 69
def to_s
super.sub(/^(file:\/)([^\/])/, '\1//\2')
end
|