Class: Halfshell::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/halfshell/agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(terminal: Terminal.default) ⇒ Agent

Returns a new instance of Agent.



4
5
6
7
8
9
# File 'lib/halfshell/agent.rb', line 4

def initialize(terminal: Terminal.default)
  @terminal = terminal;

  @try = 0
  @limit = 20
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mthd, *args, &block) ⇒ Object



56
57
58
# File 'lib/halfshell/agent.rb', line 56

def method_missing(mthd, *args, &block)
  super(mthd, *args, &block)
end

Instance Method Details

#<<(command) ⇒ Object



16
17
18
19
# File 'lib/halfshell/agent.rb', line 16

def <<(command)
  @terminal.puts command
  gets
end

#cd(*args) ⇒ Object



30
31
32
# File 'lib/halfshell/agent.rb', line 30

def cd(*args)
  @terminal.puts "cd #{args.join(' ')}"
end

#clearObject



48
# File 'lib/halfshell/agent.rb', line 48

def clear; end

#exitObject



49
# File 'lib/halfshell/agent.rb', line 49

def exit; end

#getsObject



21
22
23
# File 'lib/halfshell/agent.rb', line 21

def gets
  @terminal.gets
end

#inspectObject



52
53
54
# File 'lib/halfshell/agent.rb', line 52

def inspect
  "#<#{self.class}:#{object_id}>"
end

#ll(*args) ⇒ Object



42
43
44
# File 'lib/halfshell/agent.rb', line 42

def ll(*args)
  self.<< "ls -l #{args.join(' ')}"
end

#login?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/halfshell/agent.rb', line 25

def login?
  @terminal.puts "echo $0"
  @terminal.gets[0] == "-"
end

#ls(*args) ⇒ Object



38
39
40
# File 'lib/halfshell/agent.rb', line 38

def ls(*args)
  self.<< "ls #{args.join(' ')}"
end

#lshObject



46
# File 'lib/halfshell/agent.rb', line 46

def lsh; end

#old_inspectObject



51
# File 'lib/halfshell/agent.rb', line 51

alias :old_inspect :inspect

#puts(*what) ⇒ Object



11
12
13
14
# File 'lib/halfshell/agent.rb', line 11

def puts(*what)
  @terminal.puts(*what)
  self
end

#pwdObject



34
35
36
# File 'lib/halfshell/agent.rb', line 34

def pwd
  self.<< "pwd"
end

#respond_to_missing?(mthd, include_private = false) ⇒ Boolean

DO NOT USE THIS DIRECTLY.

Returns:

  • (Boolean)


60
61
62
# File 'lib/halfshell/agent.rb', line 60

def respond_to_missing?(mthd, include_private = false) # DO NOT USE THIS DIRECTLY.
  mthd.to_s.match? /ls|tar|ps/ || super
end

#suObject



47
# File 'lib/halfshell/agent.rb', line 47

def su; end