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
124
125
126
127
128
|
# File 'lib/yap/shell/commands.rb', line 124
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
118
119
120
121
122
|
# File 'lib/yap/shell/commands.rb', line 118
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
114
115
116
|
# File 'lib/yap/shell/commands.rb', line 114
def self.registered_functions
(@registered_functions ||= {}).freeze
end
|
Instance Method Details
#to_proc ⇒ Object
134
135
136
137
138
139
|
# File 'lib/yap/shell/commands.rb', line 134
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
130
131
132
|
# File 'lib/yap/shell/commands.rb', line 130
def type
:ShellCommand
end
|