Class: Dotfiled::AlternativeFile::File

Inherits:
Object
  • Object
show all
Defined in:
lib/dotfiled/alternative_file/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "") ⇒ File

Returns a new instance of File.



6
7
8
# File 'lib/dotfiled/alternative_file/file.rb', line 6

def initialize(path = "")
  @path = Pathname.new(path.to_s)
end

Class Method Details

.join(parts) ⇒ Object



57
58
59
60
61
# File 'lib/dotfiled/alternative_file/file.rb', line 57

def join(parts)
  file = File.new("")
  parts.flatten.each { |part| file = file.join(part) }
  file
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dotfiled/alternative_file/file.rb', line 46

def exist?
  ::File.exist?(to_s)
end

#gsub(find, replace) ⇒ Object



34
35
36
# File 'lib/dotfiled/alternative_file/file.rb', line 34

def gsub(find, replace)
  new(to_s.gsub(find, replace))
end

#join(other_part) ⇒ Object



38
39
40
# File 'lib/dotfiled/alternative_file/file.rb', line 38

def join(other_part)
  new(@path.join(other_part.to_s))
end

#match?(*args) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dotfiled/alternative_file/file.rb', line 22

def match?(*args)
  to_s.match?(*args)
end

#prefix_with(prefix) ⇒ Object



42
43
44
# File 'lib/dotfiled/alternative_file/file.rb', line 42

def prefix_with(prefix)
  new(prefix).join(self)
end

#split(char = "/") ⇒ Object



26
27
28
# File 'lib/dotfiled/alternative_file/file.rb', line 26

def split(char = "/")
  to_s.split(char)
end

#start_with?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dotfiled/alternative_file/file.rb', line 14

def start_with?(prefix)
  to_s.start_with?(prefix)
end

#sub(find, replace) ⇒ Object



30
31
32
# File 'lib/dotfiled/alternative_file/file.rb', line 30

def sub(find, replace)
  new(to_s.sub(find, replace))
end

#to_sObject



10
11
12
# File 'lib/dotfiled/alternative_file/file.rb', line 10

def to_s
  @path.to_s.gsub("//", "/")
end

#without_prefix(prefix) ⇒ Object



18
19
20
# File 'lib/dotfiled/alternative_file/file.rb', line 18

def without_prefix(prefix)
  sub(/^#{prefix}/, "")
end