class AppleBot::CommandProxy
Attributes
commands[RW]
namespace[RW]
Public Class Methods
for(command)
click to toggle source
# File lib/applebot/command_proxy.rb, line 8 def self.for(command) proxies[command.namespace] ||= new(command.namespace) proxy = proxies[command.namespace] proxy.add_command(command) proxy end
new(namespace)
click to toggle source
# File lib/applebot/command_proxy.rb, line 15 def initialize(namespace) @namespace = namespace @commands = [] end
Public Instance Methods
add_command(command)
click to toggle source
# File lib/applebot/command_proxy.rb, line 20 def add_command(command) return if @commands.include?(command.action) @commands << command.action define_singleton_method(command.action, ->(options = {}) { AppleBot.run_command(command.file_name, options) }) end
attach_to(klass)
click to toggle source
# File lib/applebot/command_proxy.rb, line 28 def attach_to(klass) return if klass.respond_to?(self.namespace) namespace = self.namespace klass.define_singleton_method(namespace) { return AppleBot::CommandProxy.proxies[namespace] } end
inspect()
click to toggle source
# File lib/applebot/command_proxy.rb, line 36 def inspect s = self.to_s.gsub(">", " ") s << "commands: #{@commands.join(', ')}" s << ">" s end