Class: Fi::Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/fi/dir.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*dirs) ⇒ Dir

Returns a new instance of Dir.



52
53
54
55
56
# File 'lib/fi/dir.rb', line 52

def initialize(*dirs)
  dirs.each do |dir|
    ::FileUtils.mkdir_p dir
  end
end

Class Method Details

.backObject



18
19
20
# File 'lib/fi/dir.rb', line 18

def self.back
  change(@history.pop || current)
end

.change(dir = home) ⇒ Object



13
14
15
16
# File 'lib/fi/dir.rb', line 13

def self.change(dir=home)
  @history << current
  ::Dir.chdir dir
end

.currentObject



6
7
8
# File 'lib/fi/dir.rb', line 6

def self.current
  ::Dir.pwd
end

.delete(dir) ⇒ Object



35
36
37
# File 'lib/fi/dir.rb', line 35

def self.delete(dir)
  FileUtils.rm_r dir
end

.delete!(dir) ⇒ Object



39
40
41
# File 'lib/fi/dir.rb', line 39

def self.delete!(dir)
  FileUtils.rm_rf dir
end

.exist?(dirname) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fi/dir.rb', line 31

def self.exist?(dirname)
  ::Dir.exist? dirname
end

.home(user = nil) ⇒ Object



47
48
49
50
# File 'lib/fi/dir.rb', line 47

def self.home(user=nil)
  return ::Dir.home user if user
  ::Dir.home
end

.list(path = current) ⇒ Object



22
23
24
25
# File 'lib/fi/dir.rb', line 22

def self.list(path=current)
  directories = list! path
  directories.reject { |d| d =~ /^\./ }
end

.list!(path = current) ⇒ Object



27
28
29
# File 'lib/fi/dir.rb', line 27

def self.list!(path=current)
  ::Dir.entries Path.expand(path)
end

.rename(dirname, name) ⇒ Object



43
44
45
# File 'lib/fi/dir.rb', line 43

def self.rename(dirname, name)
  FileUtils.mv dirname, name
end