make basic file read / write work
This commit is contained in:
parent
82ab122093
commit
33e176a353
@ -83,13 +83,19 @@ module FakeFS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.read(path)
|
||||||
|
new(path).read
|
||||||
|
end
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
def initialize(path, mode)
|
def initialize(path, mode = nil)
|
||||||
@path = path
|
@path = path
|
||||||
@mode = mode
|
@mode = mode
|
||||||
|
@file = FileSystem.find(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read
|
def read
|
||||||
|
@file.content
|
||||||
end
|
end
|
||||||
|
|
||||||
def puts(content)
|
def puts(content)
|
||||||
@ -97,8 +103,11 @@ module FakeFS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write(content)
|
def write(content)
|
||||||
FileUtils.mkdir_p(File.dirname(path))
|
if !File.exists?(@path)
|
||||||
|
@file = FileSystem.add(path, MockFile.new)
|
||||||
|
end
|
||||||
|
|
||||||
|
@file.content += content
|
||||||
end
|
end
|
||||||
alias_method :print, :write
|
alias_method :print, :write
|
||||||
end
|
end
|
||||||
@ -188,10 +197,11 @@ module FakeFS
|
|||||||
end
|
end
|
||||||
|
|
||||||
class MockFile
|
class MockFile
|
||||||
attr_accessor :name, :parent
|
attr_accessor :name, :parent, :content
|
||||||
def initialize(name = nil, parent = nil)
|
def initialize(name = nil, parent = nil)
|
||||||
@name = name
|
@name = name
|
||||||
@parent = parent
|
@parent = parent
|
||||||
|
@content = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def entry
|
def entry
|
||||||
|
Loading…
Reference in New Issue
Block a user