Class: Dire::File
Instance Attribute Summary
Attributes inherited from Node
#path, #root
Instance Method Summary
collapse
Methods inherited from Node
#get, #initialize, #parent, #to_s, #type
Constructor Details
This class inherits a constructor from Dire::Node
Instance Method Details
#binary? ⇒ Boolean
5
6
7
8
9
10
11
12
13
|
# File 'lib/dire/file.rb', line 5
def binary?
return @binary if @binary
if mime && !['application', 'text'].include?(mime.mediatype)
return @binary = true
end
@binary = !absolute_path.read.valid_encoding? rescue true
end
|
#mime ⇒ Object
15
16
17
|
# File 'lib/dire/file.rb', line 15
def mime
@mime ||= MimeMagic.by_magic absolute_path.open
end
|
#text? ⇒ Boolean
19
20
21
|
# File 'lib/dire/file.rb', line 19
def text?
!binary?
end
|
#validate! ⇒ Object
23
24
25
|
# File 'lib/dire/file.rb', line 23
def validate!
super && validate_type!('file')
end
|