Class: URI::File

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

Constant Summary collapse

COMPONENT =
[
  :scheme,
  :path
].freeze
TAR =
'tar'.to_cmd.freeze
GZIP =
'gzip'.to_cmd.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#add_query, #mk_custom_opts, #pathname, #pathname=, #to_yaml, #to_yaml_type

Constructor Details

#initialize(*args) ⇒ File

Returns a new instance of File.



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

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

Class Method Details

.build(args) ⇒ Object



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

def self.build ( args )
  tmp = Util::make_components_hash(self, args)
  return super(tmp)
end

Instance Method Details

#checkoutObject

Raises:



35
36
37
38
39
# File 'lib/uri/file.rb', line 35

def checkout
  p = self.pathname
  raise CheckoutError, to_s unless p.exist?
  p
end

#commit(aPath) ⇒ Object



41
42
43
# File 'lib/uri/file.rb', line 41

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

#saveObject

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uri/file.rb', line 45

def save
  p = self.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(self.runner)
  out
end