Class: FileSandbox::SandboxFile
- Inherits:
-
Object
- Object
- FileSandbox::SandboxFile
- Defined in:
- lib/file_sandbox.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #binary_content=(content) ⇒ Object (also: #binary_contents=)
- #content ⇒ Object (also: #contents)
- #content=(content) ⇒ Object (also: #contents=)
- #create ⇒ Object
- #exist? ⇒ Boolean (also: #exists?)
-
#initialize(path) ⇒ SandboxFile
constructor
A new instance of SandboxFile.
Constructor Details
#initialize(path) ⇒ SandboxFile
Returns a new instance of SandboxFile.
107 108 109 |
# File 'lib/file_sandbox.rb', line 107 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
105 106 107 |
# File 'lib/file_sandbox.rb', line 105 def path @path end |
Instance Method Details
#binary_content=(content) ⇒ Object Also known as: binary_contents=
124 125 126 127 |
# File 'lib/file_sandbox.rb', line 124 def binary_content=(content) FileUtils.mkdir_p File.dirname(@path) File.open(@path, "wb") {|f| f << content} end |
#content ⇒ Object Also known as: contents
115 116 117 |
# File 'lib/file_sandbox.rb', line 115 def content File.read path end |
#content=(content) ⇒ Object Also known as: contents=
119 120 121 122 |
# File 'lib/file_sandbox.rb', line 119 def content=(content) FileUtils.mkdir_p File.dirname(@path) File.open(@path, "w") {|f| f << content} end |
#create ⇒ Object
129 130 131 |
# File 'lib/file_sandbox.rb', line 129 def create self.content = '' end |
#exist? ⇒ Boolean Also known as: exists?
111 112 113 |
# File 'lib/file_sandbox.rb', line 111 def exist? File.exist? path end |