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
Class Method Details
.===(command) ⇒ Object
112
113
114
115
116
|
# File 'lib/yap/shell/commands.rb', line 112
def self.===(command)
registered_functions.detect do |name_or_pattern, *_|
name_or_pattern.match(command)
end
end
|
.define_shell_function(name_or_pattern, &blk) ⇒ Object
105
106
107
108
109
110
|
# File 'lib/yap/shell/commands.rb', line 105
def self.define_shell_function(name_or_pattern, &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)
name_or_pattern = /^#{Regexp.escape(name_or_pattern)}$/ if name_or_pattern.is_a?(String)
(@registered_functions ||= {})[name_or_pattern] = blk
end
|
.registered_functions ⇒ Object
101
102
103
|
# File 'lib/yap/shell/commands.rb', line 101
def self.registered_functions
(@registered_functions ||= {}).freeze
end
|
Instance Method Details
#to_proc ⇒ Object
122
123
124
125
126
127
|
# File 'lib/yap/shell/commands.rb', line 122
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
118
119
120
|
# File 'lib/yap/shell/commands.rb', line 118
def type
:ShellCommand
end
|