Class: Yap::Shell::BuiltinCommand
Instance Attribute Summary
Attributes inherited from Command
#args, #heredoc, #line, #str, #world
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#initialize, #to_s
Class Method Details
.===(other) ⇒ Object
48
49
50
|
# File 'lib/yap/shell/commands.rb', line 48
def self.===(other)
self.builtins.keys.include?(other.split(' ').first.to_sym) || super
end
|
.add(command, &action) ⇒ Object
60
61
62
|
# File 'lib/yap/shell/commands.rb', line 60
def self.add(command, &action)
builtins.merge!(command.to_sym => action)
end
|
.builtins ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/yap/shell/commands.rb', line 52
def self.builtins
@builtins ||= {
builtins: lambda { |stdout:, **| stdout.puts @builtins.keys.sort },
exit: lambda { |code = 0, **| exit(code.to_i) },
fg: lambda{ |**| :resume },
}
end
|
Instance Method Details
#execute(stdin:, stdout:, stderr:) ⇒ Object
64
65
66
67
|
# File 'lib/yap/shell/commands.rb', line 64
def execute(stdin:, stdout:, stderr:)
action = self.class.builtins.fetch(str.to_sym){ raise("Missing proc for builtin: '#{builtin}' in #{str.inspect}") }
action.call world:world, args:args, stdin:stdin, stdout:stdout, stderr:stderr
end
|
#to_executable_str ⇒ Object
73
74
75
|
# File 'lib/yap/shell/commands.rb', line 73
def to_executable_str
raise NotImplementedError, "#to_executable_str is not implemented on BuiltInCommand"
end
|
#type ⇒ Object
69
70
71
|
# File 'lib/yap/shell/commands.rb', line 69
def type
:BuiltinCommand
end
|