Class: ShellHelpers::VirtualFile
- Inherits:
-
Object
- Object
- ShellHelpers::VirtualFile
- Extended by:
- Forwardable
- Defined in:
- lib/shell_helpers/pathname.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tmpfile ⇒ Object
Returns the value of attribute tmpfile.
Instance Method Summary collapse
- #create(unlink = false) ⇒ Object
- #file ⇒ Object
-
#initialize(name, content) ⇒ VirtualFile
constructor
A new instance of VirtualFile.
- #path ⇒ Object
- #shellescape ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, content) ⇒ VirtualFile
Returns a new instance of VirtualFile.
596 597 598 599 600 |
# File 'lib/shell_helpers/pathname.rb', line 596 def initialize(name, content) @content=content @tmpfile=nil @name=name end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
594 595 596 |
# File 'lib/shell_helpers/pathname.rb', line 594 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
594 595 596 |
# File 'lib/shell_helpers/pathname.rb', line 594 def name @name end |
#tmpfile ⇒ Object
Returns the value of attribute tmpfile.
594 595 596 |
# File 'lib/shell_helpers/pathname.rb', line 594 def tmpfile @tmpfile end |
Instance Method Details
#create(unlink = false) ⇒ Object
611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/shell_helpers/pathname.rb', line 611 def create(unlink=false) require 'tempfile' unless @tmpfile&.path @tmpfile = Tempfile.new(@name) @tmpfile.write(@content) @tmpfile.flush end if block_given? yield path @tmpfile.close(unlink) end path end |
#file ⇒ Object
606 607 608 609 |
# File 'lib/shell_helpers/pathname.rb', line 606 def file create path end |
#path ⇒ Object
602 603 604 |
# File 'lib/shell_helpers/pathname.rb', line 602 def path @tmpfile&.path && Pathname.new(@tmpfile.path) end |
#shellescape ⇒ Object
629 630 631 632 |
# File 'lib/shell_helpers/pathname.rb', line 629 def shellescape create to_s&.shellescape end |
#to_s ⇒ Object
625 626 627 |
# File 'lib/shell_helpers/pathname.rb', line 625 def to_s @tmpfile&.path || "VirtualFile:#{@name}" end |