Class: Khaleesi::CLI::FileReader
- Inherits:
-
Object
- Object
- Khaleesi::CLI::FileReader
- Defined in:
- lib/khaleesi/cli.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(input) ⇒ FileReader
constructor
A new instance of FileReader.
- #read ⇒ Object
Constructor Details
#initialize(input) ⇒ FileReader
Returns a new instance of FileReader.
590 591 592 |
# File 'lib/khaleesi/cli.rb', line 590 def initialize(input) @input = input end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
589 590 591 |
# File 'lib/khaleesi/cli.rb', line 589 def input @input end |
Instance Method Details
#file ⇒ Object
594 595 596 597 598 599 600 601 602 603 |
# File 'lib/khaleesi/cli.rb', line 594 def file case input when '-' $stdin when String File.new(input) when ->(i){ i.respond_to? :read } input end end |
#read ⇒ Object
605 606 607 608 609 610 611 612 613 614 |
# File 'lib/khaleesi/cli.rb', line 605 def read @read ||= begin file.read rescue => e $stderr.puts "unable to open #{input}: #{e.}" exit 1 ensure file.close end end |