Module: Rails::Sh::Command
- Defined in:
- lib/rails/sh/command.rb
Class Method Summary collapse
- .[](name) ⇒ Object
- .clear ⇒ Object
- .command_names ⇒ Object
- .commands ⇒ Object
- .completion_proc ⇒ Object
- .completions ⇒ Object
- .define(*names, &block) ⇒ Object
- .find(line) ⇒ Object
Class Method Details
.[](name) ⇒ Object
28 29 30 |
# File 'lib/rails/sh/command.rb', line 28 def [](name) commands[name.to_sym] end |
.clear ⇒ Object
40 41 42 43 |
# File 'lib/rails/sh/command.rb', line 40 def clear commands.clear completions.clear end |
.command_names ⇒ Object
24 25 26 |
# File 'lib/rails/sh/command.rb', line 24 def command_names commands.keys end |
.commands ⇒ Object
5 6 7 |
# File 'lib/rails/sh/command.rb', line 5 def commands @commands ||= {} end |
.completion_proc ⇒ Object
32 33 34 |
# File 'lib/rails/sh/command.rb', line 32 def completion_proc lambda { |line| completions.grep(/#{Regexp.quote(line)}/) } end |
.completions ⇒ Object
36 37 38 |
# File 'lib/rails/sh/command.rb', line 36 def completions @completions ||= [] end |
.define(*names, &block) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rails/sh/command.rb', line 9 def define(*names, &block) names.each do |name| commands[name.to_sym] = block completions << name.to_s end end |
.find(line) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rails/sh/command.rb', line 16 def find(line) if name = line.split(/\s+/, 2)[0] commands[name.to_sym] else nil end end |