Class: SyntaxFix::DirFile
- Inherits:
-
Object
- Object
- SyntaxFix::DirFile
- Defined in:
- lib/syntax_fix/dir_file.rb
Instance Attribute Summary collapse
-
#check_exts ⇒ Object
Returns the value of attribute check_exts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #correct_file? ⇒ Boolean
-
#initialize(path) ⇒ DirFile
constructor
A new instance of DirFile.
- #is_dir? ⇒ Boolean
- #is_file? ⇒ Boolean
- #read_file ⇒ Object
- #write_file(source) ⇒ Object
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_exts ⇒ Object
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 |
#path ⇒ Object (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
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
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
15 16 17 |
# File 'lib/syntax_fix/dir_file.rb', line 15 def is_file? File.file?(@path) && !['.', '..'].include?(File.basename(@path)) end |
#read_file ⇒ Object
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 |