Class: Issuesrc::FSFile

Inherits:
Object
  • Object
show all
Defined in:
lib/issuesrc/file.rb

Overview

A file from the filesystem.

Direct Known Subclasses

GitFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FSFile

Returns a new instance of FSFile.


27
28
29
30
# File 'lib/issuesrc/file.rb', line 27

def initialize(path)
  @path = path
  @type = File.extname(path).slice(1..-1)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


25
26
27
# File 'lib/issuesrc/file.rb', line 25

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type


24
25
26
# File 'lib/issuesrc/file.rb', line 24

def type
  @type
end

Instance Method Details

#bodyObject


32
33
34
# File 'lib/issuesrc/file.rb', line 32

def body
  File.open(@path, 'r')
end

#replace_at(pos, old_content_length, new_content) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/issuesrc/file.rb', line 36

def replace_at(pos, old_content_length, new_content)
  fbody = body.read
  fbody = replace_in_string(fbody, pos, old_content_length, new_content)
  f = body_for_writing()
  f.write(fbody)
  f.close()
end