Class: Butler::Services
Overview
Plugins manages the plugins in Butler It uses
Instance Attribute Summary
Attributes included from Log::Comfort
#logger
Instance Method Summary
collapse
#debug, #error, #exception, #fail, #info, #log, #warn
Constructor Details
#initialize(butler, services_dir) ⇒ Services
Returns a new instance of Services.
22
23
24
25
26
27
28
|
# File 'lib/butler/services.rb', line 22
def initialize(butler, services_dir)
@butler = butler
@logger = butler.logger
@dir = File.expand_path(services_dir).freeze
raise ArgumentError, "#{@dir} is not a directory" unless File.directory?(@dir)
@services = {}
end
|
Instance Method Details
#[](name) ⇒ Object
61
62
63
|
# File 'lib/butler/services.rb', line 61
def [](name)
@services[name]
end
|
#load(file) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/butler/services.rb', line 36
def load(file)
rdn, name, version = file.match(%r{([^/]+)/([^/]+)/([^/]+)/service\.rb$}).captures
path = File.dirname(file)
begin
constant = "%s_%08X" % [name.camelcase, rand(0xffffffff)]
end while Butler::Services.const_defined?(constant)
service = Butler::Services.const_set(constant, Module.new)
service.extend(Butler::Service)
service.logger = @butler.logger
begin
service.load_service(@butler, path, rdn, name, version)
service.class_eval(File.read(file), file)
service.on_load
rescue Exception => e
e.extend Exception::Detailed
e.prepend "Loading service #{rdn}.#{name} #{version} failed."
exception(e)
end
end
|
#load_all ⇒ Object
30
31
32
33
34
|
# File 'lib/butler/services.rb', line 30
def load_all
Dir.glob("#{@dir}/*/*/*/service.rb") { |file|
load(file)
}
end
|
#register(service, obj) ⇒ Object
57
58
59
|
# File 'lib/butler/services.rb', line 57
def register(service, obj)
@services[service.name] = obj
end
|