class FBomb::Command
class_methods
Public Class Methods
commands()
click to toggle source
# File lib/fbomb/command.rb, line 40 def commands table.values end
load(*args)
click to toggle source
# File lib/fbomb/command.rb, line 24 def load(*args) args.flatten.uniq.each do |arg| Command.command_paths << arg case arg.to_s when %r|^[/~]| load_absolute_path(arg) when %r|://| load_uri(arg) else load_relative_path(arg) end end setup table end
load_absolute_path(arg)
click to toggle source
# File lib/fbomb/command.rb, line 66 def load_absolute_path(arg) path = File.expand_path(arg.to_s) path += '.rb' unless path =~ /\.rb\Z/ open(path){|fd| load_string(fd.read, path, 1)} end
load_relative_path(arg)
click to toggle source
# File lib/fbomb/command.rb, line 60 def load_relative_path(arg) basename = arg.to_s basename += '.rb' unless basename =~ /\.rb\Z/ load_absolute_path(File.join(Command.dir, basename)) end
load_string(string, __file__, __lineno__, dangerous = true)
click to toggle source
# File lib/fbomb/command.rb, line 72 def load_string(string, __file__, __lineno__, dangerous = true) Thread.new(string, dangerous) do |string, dangerous| Thread.current.abort_on_exception = true $SAFE = 12 unless dangerous module_eval(string, __file__, __lineno__) end.value end
load_uri(arg)
click to toggle source
# File lib/fbomb/command.rb, line 53 def load_uri(arg) uri = arg.to_s open(uri) do |fd| open(path){|fd| load_string(fd.read, uri, 1)} end end
new()
click to toggle source
# File lib/fbomb/command.rb, line 89 def initialize @call = proc{} end
setup()
click to toggle source
# File lib/fbomb/command.rb, line 44 def setup commands.each do |command| if command.setup and command.setup.respond_to?(:call) command.setup.call() command.setup = true end end end
Public Instance Methods
call(*args, &block)
click to toggle source
# File lib/fbomb/command.rb, line 93 def call(*args, &block) arity = @call.arity argv = if arity >= 0 args[0, arity] else head = [] tail = [] n = arity.abs - 1 head = args[0...n] tail = args[n..-1] [*(head + tail)] end argv.compact! block ? @call=call : instance_exec(*argv, &@call) end
call=(call)
click to toggle source
# File lib/fbomb/command.rb, line 113 def call=(call) @call = call end
matches?(*args)
click to toggle source
# File lib/fbomb/command.rb, line 141 def matches?(*args) text = Coerce.list_of_strings(args).join(' ') patterns.any?{|pattern| pattern === text} end
most_recent_comment()
click to toggle source
# File lib/fbomb/command.rb, line 125 def most_recent_comment message = catch(:message) do FBomb.messages.reverse.each do |message| next if message == FBomb.message case message['type'].to_s when 'TextMessage' throw :message, message end end nil end message['body'] if message end