Module: Fast::FilesystemObject

Included in:
Dir, File
Defined in:
lib/fast/filesystemobject.rb

Instance Method Summary collapse

Instance Method Details

#exist?(path = nil) ⇒ Boolean Also known as: exists?

Returns true if the item exists, false otherwise: relays on the implementation of a private #do_check? method in the class that includes the module

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/fast/filesystemobject.rb', line 32

def exist? path = nil
  if path
    path = normalize path
    @path = path unless @path
    do_exist? path
  else
    raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
    do_exist? @path
  end
end

#exist_all?(*args) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/fast/filesystemobject.rb', line 45

def exist_all? *args
  unless args.empty?
  else
    raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
    do_exist? @path
  end
end

#exist_any?(*args) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/fast/filesystemobject.rb', line 53

def exist_any? *args
  unless args.empty?
  else
    raise ArgumentError, "An argument should be provided if this instance has no path setted" unless @path
    do_exist? @path
  end
end

#expand(path = nil) ⇒ Object Also known as: absolute

Expands the path if it’s a relative path



21
22
23
24
25
# File 'lib/fast/filesystemobject.rb', line 21

def expand path = nil
  @path = normalize path if path
  raise Fast::PathNotSettedException, "The path was not setted in this instance" unless @path
  ::File.expand_path @path
end

#normalize(path) ⇒ Object

If a string is passed, returns the same string; if a symbol is passed, returns the string representation of the symbol; if an object of the same class as self is passed, return the #path of that object



7
8
9
10
11
12
13
# File 'lib/fast/filesystemobject.rb', line 7

def normalize path
  if path.instance_of? String or path.instance_of? Symbol
    "#{path}"
  elsif path.instance_of? self.class
    path.path
  end
end

#pathObject

Returns the path to the current FilesystemObject



16
17
18
# File 'lib/fast/filesystemobject.rb', line 16

def path
  @path
end