Class: SyntaxFix::DirFile

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_fix/dir_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DirFile

Returns a new instance of DirFile.



6
7
8
9
# File 'lib/syntax_fix/dir_file.rb', line 6

def initialize(path)
  @path = path
  @check_exts = ['rb', 'erb', 'rake', 'haml', 'slim']
end

Instance Attribute Details

#check_extsObject

Returns the value of attribute check_exts.



3
4
5
# File 'lib/syntax_fix/dir_file.rb', line 3

def check_exts
  @check_exts
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/syntax_fix/dir_file.rb', line 4

def path
  @path
end

Instance Method Details

#correct_file?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/syntax_fix/dir_file.rb', line 19

def correct_file?
  File.file?(@path) && File.writable?(@path) && check_exts.include?(File.extname(@path)[1..-1])
end

#is_dir?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/syntax_fix/dir_file.rb', line 11

def is_dir?
  File.directory?(@path) && !['.', '..'].include?(File.basename(@path))
end

#is_file?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/syntax_fix/dir_file.rb', line 15

def is_file?
  File.file?(@path) && !['.', '..'].include?(File.basename(@path))
end

#read_fileObject



27
28
29
# File 'lib/syntax_fix/dir_file.rb', line 27

def read_file
  File.open(@path, 'r') {|f| f.read}
end

#write_file(source) ⇒ Object



23
24
25
# File 'lib/syntax_fix/dir_file.rb', line 23

def write_file(source)
  File.open(@path, 'w') {|f| f.write(source)}
end