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
- .completions=(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
54 55 56 57 |
# File 'lib/rails/sh/command.rb', line 54 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 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails/sh/command.rb', line 32 def completion_proc lambda { |line| regex = /#{Regexp.quote(line)}/ completions.map { |completion| case completion when String completion if completion.match(regex) when Proc completion.call(line) end }.compact } end |
.completions ⇒ Object
46 47 48 |
# File 'lib/rails/sh/command.rb', line 46 def completions @completions ||= [] end |
.completions=(completions) ⇒ Object
50 51 52 |
# File 'lib/rails/sh/command.rb', line 50 def completions=(completions) @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 |