Class: Til::TemporaryNote
- Inherits:
-
Object
- Object
- Til::TemporaryNote
- Defined in:
- lib/til/services/note_writer.rb
Instance Attribute Summary collapse
-
#tempfile ⇒ Object
readonly
Returns the value of attribute tempfile.
Instance Method Summary collapse
- #edit(if_modified, if_unmodified) ⇒ Object
-
#initialize(tempfile = Tempfile.new(["new_note_content", ".md"])) ⇒ TemporaryNote
constructor
A new instance of TemporaryNote.
- #text ⇒ Object
- #write(text) ⇒ Object
Constructor Details
#initialize(tempfile = Tempfile.new(["new_note_content", ".md"])) ⇒ TemporaryNote
Returns a new instance of TemporaryNote.
19 20 21 |
# File 'lib/til/services/note_writer.rb', line 19 def initialize(tempfile = Tempfile.new(["new_note_content", ".md"])) @tempfile = tempfile end |
Instance Attribute Details
#tempfile ⇒ Object (readonly)
Returns the value of attribute tempfile.
17 18 19 |
# File 'lib/til/services/note_writer.rb', line 17 def tempfile @tempfile end |
Instance Method Details
#edit(if_modified, if_unmodified) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/til/services/note_writer.rb', line 31 def edit(if_modified, if_unmodified) original_text = text system(ENV["EDITOR"], path) modified_text = text if original_text == modified_text if_unmodified.call else if_modified.call(modified_text) end finish_editing end |
#text ⇒ Object
27 28 29 |
# File 'lib/til/services/note_writer.rb', line 27 def text File.read(path) end |
#write(text) ⇒ Object
23 24 25 |
# File 'lib/til/services/note_writer.rb', line 23 def write(text) File.write(path, text) end |