Class: FileSandbox::SandboxFile

Inherits:
Object
  • Object
show all
Defined in:
lib/file_sandbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

#contentObject 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

#createObject



129
130
131
# File 'lib/file_sandbox.rb', line 129

def create
  self.content = ''
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


111
112
113
# File 'lib/file_sandbox.rb', line 111

def exist?
  File.exist? path
end