# File lib/earthquake/input.rb, line 33 def alias_command(name, target) name = name.is_a?(Symbol) ? ":#{name}" : name.to_s target = target.is_a?(Symbol) ? ":#{target}" : target.to_s command_aliases[name] = target end
# File lib/earthquake/input.rb, line 89 def ask(message, prompt) puts message (Readline.readline(prompt) || "").chomp end
# File lib/earthquake/input.rb, line 94 def async_e(&block) async { handle_api_error(&block) } end
# File lib/earthquake/input.rb, line 53 def command(pattern, options = {}, &block) if block if pattern.is_a?(String) || pattern.is_a?(Symbol) command_name = ":#{pattern}" command_names << command_name if block.arity > 0 pattern = %^#{command_name}\s+(.*)$| else pattern = %^#{command_name}$| end end command_names << ":#{options[:as]}" if options[:as] commands.delete_if { |_| _[:pattern] == pattern } commands << {:pattern => pattern, :block => block} else commands.detect {|c| c[:pattern] =~ pattern} end end
# File lib/earthquake/input.rb, line 29 def command_aliases @command_aliases ||= {} end
# File lib/earthquake/input.rb, line 17 def command_names @command_names ||= Set.new end
# File lib/earthquake/input.rb, line 13 def commands @commands ||= [] end
# File lib/earthquake/input.rb, line 25 def completion(&block) completions << block end
# File lib/earthquake/input.rb, line 21 def completions @completions ||= [] end
# File lib/earthquake/input.rb, line 72 def confirm(message, type = config[:confirm_type]) s = case type when :y ask(message.u.c(:notice), "[Yn] ") when :n ask(message.u.c(:notice), "[yN] ") else raise "type must be :y or :n" end s = type.to_s if s.empty? if m = s.match(/^[yn]$/) return m[0].downcase == 'y' else confirm(message, type) end end
# File lib/earthquake/input.rb, line 98 def handle_api_error(&block) result = block.call if result["error"] error result["error"] end end
# File lib/earthquake/input.rb, line 39 def input(text) return if text.empty? input_filters.each { |f| text = f.call(text) } if command = command(text) command[:block].call(command[:pattern].match(text)) elsif !text.empty? puts "Command not found".c(43) end rescue Exception => e error e end
Generated with the Darkfish Rdoc Generator 2.