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.
73
74
75
|
# File 'lib/atheme/service.rb', line 73
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/atheme/service.rb', line 77
def method_missing(method, *args, &block)
raw_output = @session.service_call(service_name, method, *args)
if raw_output.kind_of?(Atheme::Error)
return raw_output
end
response = {raw_output: raw_output}
parser = @@parsers.has_key?(service_name) && @@parsers[service_name][method]
return Atheme::Entity.new(@session, response, &block) unless parser
parser.commands.each do |command|
response[command.name] = command.call(@session, raw_output)
end
return parser.responder.new(@session, response, &block) if parser.responder
return response
end
|
Class Method Details
.command(name, opts = {}, &block) ⇒ Object
65
66
67
|
# File 'lib/atheme/service.rb', line 65
def self.command(name, opts={}, &block)
@@staged_parser.register_command(Atheme::Service::Command.new(name, opts, &block))
end
|
.inherited(klass) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/atheme/service.rb', line 47
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
58
59
60
61
62
63
|
# File 'lib/atheme/service.rb', line 58
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
69
70
71
|
# File 'lib/atheme/service.rb', line 69
def self.responds_with(atheme_class)
@@staged_parser.responder = atheme_class
end
|