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
26
# File 'lib/memfs/fake/file/content.rb', line 20

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

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



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

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

#to_sObject



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

def to_s
  @string
end

#truncate(length) ⇒ Object



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

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

#write(string) ⇒ Object



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

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