Class: URI::File

Inherits:
GenericEx show all
Defined in:
lib/uri/file.rb

Constant Summary collapse

COMPONENT =
[
  :scheme,
  :path
].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.



20
21
22
23
24
25
26
# File 'lib/uri/file.rb', line 20

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

#checkoutObject

Raises:



28
29
30
31
32
# File 'lib/uri/file.rb', line 28

def checkout
  p = pathname
  raise CheckoutError, to_s unless p.exist?
  [p, nil]
end

#commit(aPath) ⇒ Object



34
35
36
# File 'lib/uri/file.rb', line 34

def commit ( aPath )
  aPath.cp_r(self.pathname)
end

#fingerprintObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/uri/file.rb', line 51

def fingerprint
  digest = Digest::MD5.new
  if pathname.directory?
    pathname.find do |path|
      next if path.directory? or not path.readable?
      digest << path.read
    end
  else
    digest << pathname.read
  end
  digest.to_s
end

#saveObject

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uri/file.rb', line 38

def save
  p = pathname
  raise SaveError, to_s unless p.exist?
  if p.directory?
    out = TempPath.new('save', "#{p.basename}.tar.gz")
    shell! { tar 'czf', out, p }
  else
    out = TempPath.new('save', "#{p.basename}.gz")
    shell! { gzip('-c', p) > out }
  end
  [out, nil]
end

#to_sObject



64
65
66
# File 'lib/uri/file.rb', line 64

def to_s
  super.sub(/^(file:\/)([^\/])/, '\1//\2')
end