Module: Cardigan::Context
- Included in:
- EntryContext, RootContext, WorkflowContext
- Defined in:
- lib/cardigan/context.rb
Instance Method Summary collapse
- #command(name, *args) ⇒ Object
- #process_command(name, parameter = nil) ⇒ Object
- #push ⇒ Object
- #refresh ⇒ Object
Instance Method Details
#command(name, *args) ⇒ Object
10 11 12 13 |
# File 'lib/cardigan/context.rb', line 10 def command name, *args require "cardigan/command/#{name}" Command.const_get(name.to_s.camelize).new(*args) end |
#process_command(name, parameter = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cardigan/context.rb', line 47 def process_command name, parameter=nil m = "#{name}_command".to_sym if respond_to?(m) send(m, parameter) return end if @commands[name] @commands[name].execute parameter else @io.say 'unknown command' end end |
#push ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cardigan/context.rb', line 23 def push refresh begin while line = Readline.readline(@prompt_text, true) line.strip! case line when 'quit','exit' return when /(\w+) (.*)/ process_command $1, $2 when /(\w+)/ process_command $1 else puts 'unknown command' end puts refresh end rescue Interrupt => e return end puts end |
#refresh ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/cardigan/context.rb', line 15 def refresh commands = respond_to?(:refresh_commands) ? refresh_commands : [] Readline.completion_proc = lambda do |text| (commands + @commands.keys + ['quit', 'exit']).grep( /^#{Regexp.escape(text)}/ ).sort end Readline.completer_word_break_characters = '' end |