Class: Forematter::FileWrapper
- Inherits:
-
Object
- Object
- Forematter::FileWrapper
- Extended by:
- Forwardable
- Defined in:
- lib/forematter/file_wrapper.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(filename) ⇒ FileWrapper
constructor
A new instance of FileWrapper.
- #to_s ⇒ Object
- #write ⇒ Object
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
#filename ⇒ Object (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
#content ⇒ Object
24 25 26 27 |
# File 'lib/forematter/file_wrapper.rb', line 24 def content parse_file @content end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/forematter/file_wrapper.rb', line 16 def to_s "#{.to_yaml}---\n#{content}" end |
#write ⇒ Object
20 21 22 |
# File 'lib/forematter/file_wrapper.rb', line 20 def write File.open(filename, 'w+') { |f| f << to_s } end |