Class: MemFs::Fake::File::Content

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/memfs/fake/file/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = '') ⇒ Content

Returns a new instance of Content.



13
14
15
16
17
18
# File 'lib/memfs/fake/file/content.rb', line 13

def initialize(obj = '')
  @string = obj.to_s.dup
  @pos = 0

  __setobj__ @string
end

Instance Attribute Details

#posObject

Returns the value of attribute pos.



8
9
10
# File 'lib/memfs/fake/file/content.rb', line 8

def pos
  @pos
end

Instance Method Details

#closeObject



10
11
# File 'lib/memfs/fake/file/content.rb', line 10

def close
end

#puts(*strings) ⇒ Object



20
21
22
23
24
25
# File 'lib/memfs/fake/file/content.rb', line 20

def puts(*strings)
  strings.each do |str|
    @string << str
    @string << $/ unless str.end_with?($/)
  end
end

#read(length = nil, buffer = '') ⇒ Object



27
28
29
30
31
32
# File 'lib/memfs/fake/file/content.rb', line 27

def read(length = nil, buffer = '')
  length ||= @string.length - @pos
  buffer.replace @string[@pos, length]
  @pos += buffer.bytesize
  buffer.empty? ? nil : buffer
end

#to_sObject



38
39
40
# File 'lib/memfs/fake/file/content.rb', line 38

def to_s
  @string
end

#truncate(length) ⇒ Object



34
35
36
# File 'lib/memfs/fake/file/content.rb', line 34

def truncate(length)
  @string.replace @string[0, length]
end

#write(string) ⇒ Object



42
43
44
45
46
# File 'lib/memfs/fake/file/content.rb', line 42

def write(string)
  text = string.to_s
  @string << text
  text.size
end