Module: Vimpack::Utils::File

Included in:
Commands::Command, Models::Base, Models::Repo
Defined in:
lib/vimpack/utils/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bundle_pathObject

Returns the value of attribute bundle_path.



6
7
8
# File 'lib/vimpack/utils/file.rb', line 6

def bundle_path
  @bundle_path
end

#home_pathObject

Returns the value of attribute home_path.



6
7
8
# File 'lib/vimpack/utils/file.rb', line 6

def home_path
  @home_path
end

#pack_pathObject

Returns the value of attribute pack_path.



6
7
8
# File 'lib/vimpack/utils/file.rb', line 6

def pack_path
  @pack_path
end

#script_pathObject

Returns the value of attribute script_path.



6
7
8
# File 'lib/vimpack/utils/file.rb', line 6

def script_path
  @script_path
end

#vim_pathObject

Returns the value of attribute vim_path.



6
7
8
# File 'lib/vimpack/utils/file.rb', line 6

def vim_path
  @vim_path
end

Instance Method Details



28
29
30
31
32
33
# File 'lib/vimpack/utils/file.rb', line 28

def create_link(target, linkname, relative=true)
  target = Pathname.new(target).relative_path_from(
    Pathname.new(::File.dirname(linkname))
  ) if relative
  ::FileUtils.ln_s(target, linkname)
end

#directory_exists?(directory) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/vimpack/utils/file.rb', line 20

def directory_exists?(directory)
  ::File::directory?(directory)
end

#file_exists?(filename) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/vimpack/utils/file.rb', line 16

def file_exists?(filename)
  ::File.exists?(filename)
end

#make_dir(*paths) ⇒ Object



48
49
50
# File 'lib/vimpack/utils/file.rb', line 48

def make_dir(*paths)
  ::FileUtils.mkdir_p(*paths)
end

#move_path(source, target) ⇒ Object



44
45
46
# File 'lib/vimpack/utils/file.rb', line 44

def move_path(source, target)
  ::FileUtils.mv(source, target) if file_exists?(source)
end

#remove_directory(directory) ⇒ Object



39
40
41
42
# File 'lib/vimpack/utils/file.rb', line 39

def remove_directory(directory)
  exit_with_error!("no way!") if directory == '/'
  ::FileUtils.rmtree(directory)
end


35
36
37
# File 'lib/vimpack/utils/file.rb', line 35

def remove_link(link)
  ::FileUtils.rm(link)
end

#setup_paths(home_path) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/vimpack/utils/file.rb', line 8

def setup_paths(home_path)
  self.home_path   = FilePath.new(home_path)
  self.pack_path   = FilePath.new(self.home_path.join('.vimpack'))
  self.script_path = FilePath.new(self.pack_path.join('scripts'))
  self.vim_path    = FilePath.new(self.pack_path.join('vim'))
  self.bundle_path = FilePath.new(self.vim_path.join('bundle'))
end

Returns:

  • (Boolean)


24
25
26
# File 'lib/vimpack/utils/file.rb', line 24

def symlink_exists?(linkname)
  ::File.exists?(linkname) && ::File.stat(linkname).symlink?
end

#template(name, path) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/vimpack/utils/file.rb', line 56

def template(name, path)
  name = name + '.erb'
  contents = ::ERB.new(::File.read(template_path(name))).result(binding)
  target = ::File.open(path, 'w')
  target.write(contents)
  target.close
end

#template_path(*path) ⇒ Object



52
53
54
# File 'lib/vimpack/utils/file.rb', line 52

def template_path(*path)
  Vimpack.root.join('templates', *path)
end