Class: Atheme::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/atheme/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Service

Returns a new instance of Service.



4
5
6
# File 'lib/atheme/service.rb', line 4

def initialize(output)
  @raw_services_output = output
end

Instance Attribute Details

#raw_services_outputObject (readonly)

Returns the value of attribute raw_services_output.



2
3
4
# File 'lib/atheme/service.rb', line 2

def raw_services_output
  @raw_services_output
end

Class Method Details

.create_service_object(method, service, atheme_data) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/atheme/service.rb', line 12

def self.create_service_object(method, service, atheme_data)
  if parser_for?(service, method)
    parser = Atheme::Support.constantize("Atheme::Parser::#{service}::#{method.capitalize}")

    self.new(atheme_data).extend(parser)
  else
    self.new(atheme_data)
  end
end

.inherited(klass) ⇒ Object



8
9
10
# File 'lib/atheme/service.rb', line 8

def self.inherited(klass)
  Atheme::SERVICES << klass.name.gsub('Atheme::', '')
end

.method_missing(method, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/atheme/service.rb', line 22

def self.method_missing(method, *args, &block)
  raise Atheme::Error::InvalidUser, 'No user has been set' if Atheme.user.nil?

  service = self.name.gsub('Atheme::', '')

  self.create_service_object(method, service, Atheme.call('atheme.command',
    Atheme.user.cookie, Atheme.user.username, Atheme.user.ip,
    service, method, *args))
end

.parser_for?(service, command) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/atheme/service.rb', line 32

def self.parser_for?(service, command)
  if Atheme::PARSERS.include?(service)
    Atheme::PARSERS[service].include?(command.to_s)
  else
    false
  end
end