class Rohbau::Runtime

Public Class Methods

new() click to toggle source
# File lib/rohbau/runtime.rb, line 21
def initialize
  on_boot
  initialize_plugins
  after_boot
end
plugins() click to toggle source
# File lib/rohbau/runtime.rb, line 17
def self.plugins
  @plugins ||= {}
end
register(name, plugin_class) click to toggle source
# File lib/rohbau/runtime.rb, line 6
def self.register(name, plugin_class)
  attr_reader name
  plugins[name] = plugin_class
  plugin_class.registered(self) if plugin_class.respond_to?(:registered)
end
unregister(name) click to toggle source
# File lib/rohbau/runtime.rb, line 12
def self.unregister(name)
  remove_method name
  plugins.delete name
end

Public Instance Methods

root() click to toggle source
# File lib/rohbau/runtime.rb, line 32
def root
  Pathname.new(Dir.pwd)
end
terminate() click to toggle source
# File lib/rohbau/runtime.rb, line 27
def terminate
  terminate_plugins
  after_termination
end

Protected Instance Methods

after_boot() click to toggle source
# File lib/rohbau/runtime.rb, line 42
def after_boot
  # noop
end
after_termination() click to toggle source
# File lib/rohbau/runtime.rb, line 46
def after_termination
end
handle_transaction(&block) click to toggle source
# File lib/rohbau/runtime.rb, line 71
def handle_transaction(&block)
  if transaction_handling_plugin
    transaction_handling_plugin.transaction_handler(&block)
  else
    block.call
  end
end
initialize_plugins() click to toggle source
# File lib/rohbau/runtime.rb, line 49
def initialize_plugins
  self.class.plugins.each do |name, plugin_class|
    instance_variable_set :"@#{name}", plugin_class.new
  end
end
notify_plugins(message, *args) click to toggle source
# File lib/rohbau/runtime.rb, line 55
def notify_plugins(message, *args)
  self.class.plugins.each do |name, _|
    plugin = public_send(name)
    if plugin.instance.respond_to? message
      plugin.instance.public_send(message, *args)
    end
  end
end
on_boot() click to toggle source
# File lib/rohbau/runtime.rb, line 38
def on_boot
  # noop
end
terminate_plugins() click to toggle source
# File lib/rohbau/runtime.rb, line 64
def terminate_plugins
  self.class.plugins.each do |name, _|
    plugin = public_send(name)
    plugin.terminate if plugin.respond_to? :terminate
  end
end
transaction_handling_plugin() click to toggle source
# File lib/rohbau/runtime.rb, line 79
def transaction_handling_plugin
  return @handling_plugin if defined? @handling_plugin

  plugin = self.class.plugins.detect do |_, runtime_loader|
    runtime_loader.instance.respond_to? :transaction_handler
  end
  if plugin
    @handling_plugin = plugin[1].instance
  else
    @handling_plugin = nil
  end
end