Class: Gitomator::BaseContext
- Inherits:
-
Object
- Object
- Gitomator::BaseContext
- Defined in:
- lib/gitomator/context.rb
Overview
Register service-factories, and create services.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(config) ⇒ BaseContext
constructor
A new instance of BaseContext.
- #register_service(service, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ BaseContext
Returns a new instance of BaseContext.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gitomator/context.rb', line 15 def initialize(config) @config = config @service2factory = {} @services = {} config.select { |_,v| v.is_a?(Hash) && v.has_key?('provider')} .each do |service, service_config| register_service(service.to_sym) do |config| self.send("create_#{config['provider']}_#{service}_service", config || {}) end end end |
Instance Method Details
#register_service(service, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitomator/context.rb', line 34 def register_service(service, &block) @service2factory[service] = block # Create a lazy-loader getter for the service unless self.respond_to? service self.class.send(:define_method, service) do @services[service] ||= @service2factory[service].call(@config[service.to_s] || {}) end end end |