Module: IMW::Schemes::Local::Base

Defined in:
lib/imw/schemes/local.rb

Overview

Defines methods appropriate for any file (or directory) on the local machine. Includes methods from the File class like File#exist?, File#size, &c.

When extending with this module, it will automatically also extend with either IMW::Schemes::Local::LocalDirectory or IMW::Schemes::Local::LocalFile, as appropriate.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/imw/schemes/local.rb', line 14

def self.extended obj
  # also extend with file or directory as appropriate
  if obj.directory?
    obj.extend(LocalDirectory)
  else
    obj.extend(LocalFile)
  end
end

Instance Method Details

#cp(new_uri) ⇒ IMW::Resource

Copy this resource to the new_uri.

Parameters:

Returns:



50
51
52
# File 'lib/imw/schemes/local.rb', line 50

def cp new_uri
  IMW::Tools::Transferer.new(:cp, self, new_uri).transfer!
end

#dirIMW::Resource

Return the directory of this resource.

Returns:



65
66
67
# File 'lib/imw/schemes/local.rb', line 65

def dir
  IMW.open(dirname)
end

#is_local?true, false

Is this file on the local machine?

Returns:

  • (true, false)


42
43
44
# File 'lib/imw/schemes/local.rb', line 42

def is_local?
  true
end

#mv(new_uri) ⇒ IMW::Resource

Move this resource to the new_uri.

Parameters:

Returns:



58
59
60
# File 'lib/imw/schemes/local.rb', line 58

def mv new_uri
  IMW::Tools::Transferer.new(:mv, self, new_uri).transfer!
end

#pathString

Return the path to this local object.

Returns:



35
36
37
# File 'lib/imw/schemes/local.rb', line 35

def path
  @path ||= File.expand_path(@encoded_uri ? Addressable::URI.decode(uri.to_s) : uri.to_s)
end