Class: Dash::Session
- Includes:
- BuiltinMod, FromHash
- Defined in:
- lib/dash/session.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
Instance Method Summary collapse
- #dir_exists?(dir) ⇒ Boolean
- #dispatch(str) ⇒ Object
- #prompt ⇒ Object
- #run! ⇒ Object
- #run_in_docker(cmd) ⇒ Object
- #run_line(line) ⇒ Object
Methods included from BuiltinMod
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
31 32 33 |
# File 'lib/dash/session.rb', line 31 def image @image end |
Instance Method Details
#dir_exists?(dir) ⇒ Boolean
53 54 55 |
# File 'lib/dash/session.rb', line 53 def dir_exists?(dir) #run_in_docker "if test -d #{dir}; then echo 'exist'; fi " end |
#dispatch(str) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dash/session.rb', line 70 def dispatch(str) parts = str.split(" ") name = parts[0] args = parts[1..-1] if builtin?(name) dispatch_builtin(name,*args) else run_in_docker(str) end end |
#prompt ⇒ Object
82 83 84 |
# File 'lib/dash/session.rb', line 82 def prompt "#{image} | #{current_dir} ~> " end |
#run! ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/dash/session.rb', line 92 def run! print prompt loop do line = STDIN.gets run_line line end end |
#run_in_docker(cmd) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dash/session.rb', line 57 def run_in_docker(cmd) #puts "RID: current_dir: #{current_dir}, cmd: #{cmd}" raise "no image" unless image.present? cmd = "docker run -w #{current_dir} #{image} #{cmd}" puts "RID: #{cmd}" pid = fork do exec cmd end Process.wait pid end |
#run_line(line) ⇒ Object
86 87 88 89 90 |
# File 'lib/dash/session.rb', line 86 def run_line(line) res = dispatch(line) #puts res if res.present? print prompt end |