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.



108
109
110
# File 'lib/file_sandbox.rb', line 108

def initialize(path)
  @path = path
end

Instance Attribute Details

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

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

#createObject



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

def create
  self.content = ''
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


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

def exist?
  File.exist? path
end