Class: Shr::Shell

Inherits:
Object
  • Object
show all
Includes:
Builtin
Defined in:
lib/shr/shell.rb

Instance Method Summary collapse

Methods included from Builtin

#capture, #cd!

Constructor Details

#initializeShell

Returns a new instance of Shell.



10
11
12
# File 'lib/shr/shell.rb', line 10

def initialize
  @commands = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/shr/shell.rb', line 14

def method_missing(name, *args)
  command = Command.new(name, args)
  unless command.exist?
    super
  else
    delay command
    force if command.release?
    self
  end
end

Instance Method Details

#bake(name, command, options = []) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/shr/shell.rb', line 67

def bake(name, command, options=[])
  Shell.class_eval do
    define_method(name) do |*args|
      self.method_missing(command, *(options + args))
    end
  end
end

#eachObject



40
41
42
43
44
45
# File 'lib/shr/shell.rb', line 40

def each
  force
  if filled?
    block_given? ? @command_out.each { |ln| yield ln } : @command_out.each
  end
end

#exitstatusObject



47
48
49
50
51
52
53
# File 'lib/shr/shell.rb', line 47

def exitstatus
  force
  if @wait_thread
    proc = @wait_thread.value
    proc.exitstatus
  end
end

#inspectObject



30
31
32
33
34
35
36
37
38
# File 'lib/shr/shell.rb', line 30

def inspect
  command_line = @commands.map {|c| c.first }.join(' | ').strip
  force
  res =  "#<Shr::Shell>"
  res << "<:command => #{command_line}>" if command_line.size > 0
  res << "\n" if filled?
  res << @command_out.read if filled?
  res
end

#redirect_from(src) ⇒ Object Also known as: <



55
56
57
58
# File 'lib/shr/shell.rb', line 55

def redirect_from(src)
  force(:in => src)
  self
end

#redirect_to(dest) ⇒ Object Also known as: >



60
61
62
# File 'lib/shr/shell.rb', line 60

def redirect_to(dest)
  force(:out => dest)
end

#to_sObject



25
26
27
28
# File 'lib/shr/shell.rb', line 25

def to_s
  force
  @command_out.read if filled?
end