Module: Pry::Tad

Defined in:
lib/pry/tad.rb,
lib/pry/tad/version.rb

Overview

namespace

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.run(argf: ARGF) ⇒ Object



31
32
33
# File 'lib/pry/tad.rb', line 31

def run(argf: ARGF)
  run_argf if argf
end

.run_argf(argf) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pry/tad.rb', line 35

def run_argf(argf)
  if argf.filename == '-'
    File.open(tmp_file_path, 'wb') do |f|
      while (chunk = argf.read(1024 * 8))
        f.write(chunk)
      end
      start_tad(f.path)
    end
  else
    start_tad(argf.filename)
  end
end

.start_tad(filename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pry/tad.rb', line 19

def start_tad(filename)
  return if system('tad', filename)
  $stderr.puts <<-TEXT
Couldn't start `tad` make sure it is installed.
Install on OSX using:
```sh
brew install cask
brew cask install tad
```
  TEXT
end

.tmp_file_pathObject

temporory file path with name



15
16
17
# File 'lib/pry/tad.rb', line 15

def tmp_file_path
  File.join(Dir.tmpdir, "#{tmp_name}.csv")
end

.tmp_nameObject

temporary file name



10
11
12
# File 'lib/pry/tad.rb', line 10

def tmp_name
  Time.now.strftime('%Y%m%d%H%M%S')
end