Class: FFFS::File
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filesystem ⇒ Object
Returns the value of attribute filesystem.
-
#mime ⇒ Object
Returns the value of attribute mime.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #chmod(mode) ⇒ Object
- #execute(*args) ⇒ Object
-
#initialize(name, content = '', parent = nil, filesystem = nil) ⇒ File
constructor
A new instance of File.
- #inspect ⇒ Object
- #save(file, mode = nil) ⇒ Object
- #to_s ⇒ Object
Methods included from Node
Constructor Details
#initialize(name, content = '', parent = nil, filesystem = nil) ⇒ File
Returns a new instance of File.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fffs/file.rb', line 32 def initialize (name, content='', parent=nil, filesystem=nil) @filesystem = filesystem @parent = parent @name = name @mode = 0644 @mime = 'text/plain' @content = content.clone @content.force_encoding('ASCII-8BIT') rescue nil end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
29 30 31 |
# File 'lib/fffs/file.rb', line 29 def content @content end |
#filesystem ⇒ Object
Returns the value of attribute filesystem.
27 28 29 |
# File 'lib/fffs/file.rb', line 27 def filesystem @filesystem end |
#mime ⇒ Object
Returns the value of attribute mime.
29 30 31 |
# File 'lib/fffs/file.rb', line 29 def mime @mime end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
30 31 32 |
# File 'lib/fffs/file.rb', line 30 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/fffs/file.rb', line 30 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
27 28 29 |
# File 'lib/fffs/file.rb', line 27 def parent @parent end |
Instance Method Details
#chmod(mode) ⇒ Object
50 51 52 |
# File 'lib/fffs/file.rb', line 50 def chmod (mode) @mode = mode end |
#execute(*args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fffs/file.rb', line 79 def execute (*args) require 'tempfile' tmp = Tempfile.new('fffs') tmp.chmod 0700 save(tmp) tmp.close Kernel.system(tmp.path, *args) ensure tmp.unlink end |
#inspect ⇒ Object
98 99 100 |
# File 'lib/fffs/file.rb', line 98 def inspect self.path end |
#save(file, mode = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fffs/file.rb', line 54 def save (file, mode=nil) result = true if file.is_a?(String) ::File.open(file, 'wb') {|f| result = f.write content begin f.chmod(mode || @mode) rescue Exception => e end } else result = file.write content file.flush begin file.chmod(mode || @mode) rescue Exception => e end end result end |
#to_s ⇒ Object
94 95 96 |
# File 'lib/fffs/file.rb', line 94 def to_s @content end |