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

def initialize(obj = '')
  super

  @string = obj.to_s.dup
  @pos = 0

  __setobj__ @string
end

Instance Attribute Details

#posObject

Returns the value of attribute pos.



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

def pos
  @pos
end

Instance Method Details

#closeObject



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

def close; end

#puts(*strings) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/memfs/fake/file/content.rb', line 22

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

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



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

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

#to_sObject



41
42
43
# File 'lib/memfs/fake/file/content.rb', line 41

def to_s
  @string
end

#truncate(length) ⇒ Object



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

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

#write(string) ⇒ Object



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

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