Class: AppleBot::CommandProxy
- Inherits:
-
Object
- Object
- AppleBot::CommandProxy
- Defined in:
- lib/applebot/command_proxy.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Class Method Summary collapse
Instance Method Summary collapse
- #add_command(command) ⇒ Object
- #attach_to(klass) ⇒ Object
-
#initialize(namespace) ⇒ CommandProxy
constructor
A new instance of CommandProxy.
- #inspect ⇒ Object
Constructor Details
#initialize(namespace) ⇒ CommandProxy
Returns a new instance of CommandProxy.
15 16 17 18 |
# File 'lib/applebot/command_proxy.rb', line 15 def initialize(namespace) @namespace = namespace @commands = [] end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
6 7 8 |
# File 'lib/applebot/command_proxy.rb', line 6 def commands @commands end |
#namespace ⇒ Object
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/applebot/command_proxy.rb', line 6 def namespace @namespace end |
Class Method Details
.for(command) ⇒ Object
8 9 10 11 12 13 |
# 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 |
Instance Method Details
#add_command(command) ⇒ Object
20 21 22 23 24 25 26 |
# 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, ->( = {}) { AppleBot.run_command(command.file_name, ) }) end |
#attach_to(klass) ⇒ Object
28 29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 39 40 41 |
# File 'lib/applebot/command_proxy.rb', line 36 def inspect s = self.to_s.gsub(">", " ") s << "commands: #{@commands.join(', ')}" s << ">" s end |