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.
108 109 110 |
# File 'lib/file_sandbox.rb', line 108 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
106 107 108 |
# File 'lib/file_sandbox.rb', line 106 def path @path end |
Instance Method Details
#binary_content=(content) ⇒ Object Also known as: binary_contents=
125 126 127 128 |
# File 'lib/file_sandbox.rb', line 125 def binary_content=(content) FileUtils.mkdir_p File.dirname(@path) File.open(@path, "wb") {|f| f << content} end |
#content ⇒ Object Also known as: contents
116 117 118 |
# File 'lib/file_sandbox.rb', line 116 def content File.read path end |
#content=(content) ⇒ Object Also known as: contents=
120 121 122 123 |
# File 'lib/file_sandbox.rb', line 120 def content=(content) FileUtils.mkdir_p File.dirname(@path) File.open(@path, "w") {|f| f << content} end |
#create ⇒ Object
130 131 132 |
# File 'lib/file_sandbox.rb', line 130 def create self.content = '' end |
#exist? ⇒ Boolean Also known as: exists?
112 113 114 |
# File 'lib/file_sandbox.rb', line 112 def exist? File.exist? path end |