# 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 88 def ask(message) print message (STDIN.gets || "").chomp end
# File lib/earthquake/input.rb, line 93 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 << {: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 71 def confirm(message, type = config[:confirm_type]) s = case type when :y ask("#{message} [Yn] ".u) when :n ask("#{message} [yN] ".u) 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 97 def handle_api_error(&block) result = block.call if result["error"] notify "[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.