Class: Yap::Shell::ShellCommand
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_executable_str, #to_s
Class Method Details
.===(command) ⇒ Object
136
137
138
139
140
|
# File 'lib/yap/shell/commands.rb', line 136
def self.===(command)
registered_functions.detect do |name_or_pattern, *_|
name_or_pattern.match(command)
end
end
|
.define_shell_function(name_or_pattern, name: nil, &blk) ⇒ Object
130
131
132
133
134
|
# File 'lib/yap/shell/commands.rb', line 130
def self.define_shell_function(name_or_pattern, name: nil, &blk)
raise ArgumentError, "Must provide block when defining a shell function" unless blk
name_or_pattern = name_or_pattern.to_s if name_or_pattern.is_a?(Symbol)
(@registered_functions ||= {})[name_or_pattern] = blk
end
|
.registered_functions ⇒ Object
126
127
128
|
# File 'lib/yap/shell/commands.rb', line 126
def self.registered_functions
(@registered_functions ||= {}).freeze
end
|
Instance Method Details
#to_proc ⇒ Object
146
147
148
149
150
151
|
# File 'lib/yap/shell/commands.rb', line 146
def to_proc
self.class.registered_functions.detect do |name_or_pattern, function_body|
return function_body if name_or_pattern.match(str)
end
raise "Shell function #{str} was not found!"
end
|
#type ⇒ Object
142
143
144
|
# File 'lib/yap/shell/commands.rb', line 142
def type
:ShellCommand
end
|