Class: Atheme::Service
- Inherits:
-
Object
show all
- Defined in:
- lib/atheme/service.rb
Direct Known Subclasses
ChanServ, GameServ, Global, GroupServ, HelpServ, HostServ, InfoServ, MemoServ, NickServ, OperServ, RPGServ, StatServ
Defined Under Namespace
Classes: Command, Parser
Constant Summary
collapse
- @@parsers =
Hash.new
- @@tmp_commands =
[]
- @@tmp_class =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(session) ⇒ Service
Returns a new instance of Service.
74
75
76
|
# File 'lib/atheme/service.rb', line 74
def initialize(session)
@session = session
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/atheme/service.rb', line 78
def method_missing(method, *args, &block)
raw_output = @session.service_call(service_name, method, *args)
response = {raw_output: raw_output}
parser = @@parsers.has_key?(service_name) && @@parsers[service_name][method]
return Atheme::Entity.new(@session, response) unless parser
parser.commands.each do |command|
response[command.name] = command.call(@session, raw_output)
end
parser.responder.new(@session, response) if parser.responder
end
|
Class Method Details
.command(name, opts = {}, &block) ⇒ Object
66
67
68
|
# File 'lib/atheme/service.rb', line 66
def self.command(name, opts={}, &block)
@@staged_parser.register_command(Atheme::Service::Command.new(name, opts, &block))
end
|
.inherited(klass) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/atheme/service.rb', line 48
def self.inherited(klass)
class_name = klass.name.gsub('Atheme::', '')
Atheme::Session.class_eval <<-RUBY
def #{class_name.downcase}
@#{class_name.downcase} ||= #{klass.name}.new(self)
end
RUBY
@@parsers[class_name.downcase] ||= Hash.new
end
|
.parse(cmd, &block) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/atheme/service.rb', line 59
def self.parse(cmd, &block)
service = self.name.sub('Atheme::', '').downcase
@@parsers[service][cmd] = Atheme::Service::Parser.new
@@staged_parser = @@parsers[service][cmd]
yield if block_given?
end
|
.responds_with(atheme_class) ⇒ Object
70
71
72
|
# File 'lib/atheme/service.rb', line 70
def self.responds_with(atheme_class)
@@staged_parser.responder = atheme_class
end
|