Class: Forematter::FileWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/forematter/file_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FileWrapper

Returns a new instance of FileWrapper.



7
8
9
10
# File 'lib/forematter/file_wrapper.rb', line 7

def initialize(filename)
  fail Forematter::UnexpectedValue, "File not found: #{filename}" unless File.file?(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/forematter/file_wrapper.rb', line 12

def filename
  @filename
end

Instance Method Details

#contentObject



24
25
26
27
# File 'lib/forematter/file_wrapper.rb', line 24

def content
  parse_file
  @content
end

#to_sObject



16
17
18
# File 'lib/forematter/file_wrapper.rb', line 16

def to_s
  "#{meta.to_yaml}---\n#{content}"
end

#writeObject



20
21
22
# File 'lib/forematter/file_wrapper.rb', line 20

def write
  File.open(filename, 'w+') { |f| f << to_s }
end