module BR

Constants

ALLOWED_MODES
DEFAULT_MODE
DEFAULT_PORT
VERSION

Attributes

config[R]
plugins[R]

Public Instance Methods

initialize!(options = {}) click to toggle source
# File lib/blade_runner.rb, line 69
def initialize!(options = {})
  return if initialized?
  @options = options.with_indifferent_access
  load_config_file!
  read_arguments!
  setup_config!
  setup_adapter!
  setup_plugins!
  @initialized = true
end
initialized?() click to toggle source
# File lib/blade_runner.rb, line 80
def initialized?
  @initialized
end
interface() click to toggle source
# File lib/blade_runner.rb, line 88
def interface
  @interface ||=
    case config.mode
    when :ci then CI
    when :console then Console
    end
end
register_component(component) click to toggle source
# File lib/blade_runner.rb, line 16
def register_component(component)
  @components << component
end
root_path() click to toggle source
# File lib/blade_runner.rb, line 96
def root_path
  Pathname.new(File.dirname(__FILE__)).join("../")
end
running?() click to toggle source
# File lib/blade_runner.rb, line 65
def running?
  @running
end
start(options = {}) click to toggle source
# File lib/blade_runner.rb, line 45
def start(options = {})
  return if running?
  initialize!(options)
  handle_exit
  interface

  EM.run do
    @components.each { |c| c.start if c.respond_to?(:start) }
    @running = true
  end
end
stop() click to toggle source
# File lib/blade_runner.rb, line 57
def stop
  return if @stopping
  @stopping = true
  @components.each { |c| c.stop if c.respond_to?(:stop) }
  EM.stop if EM.reactor_running?
  @running = false
end
tmp_path() click to toggle source
# File lib/blade_runner.rb, line 100
def tmp_path
  Pathname.new(".").join("tmp/blade_runner")
end
url(path = "") click to toggle source
# File lib/blade_runner.rb, line 84
def url(path = "")
  "http://localhost:#{config.port}#{path}"
end

Private Instance Methods

handle_exit() click to toggle source
# File lib/blade_runner.rb, line 105
def handle_exit
  %w( INT ).each do |signal|
    trap(signal) { stop }
  end

  at_exit do
    stop
    exit $!.status if $!.is_a?(SystemExit)
  end
end
load_config_file!() click to toggle source
# File lib/blade_runner.rb, line 116
def load_config_file!
  filename = ".blade.yml"
  if File.exists?(filename)
    @options.reverse_merge!(YAML.load_file(filename))
  end
end
read_arguments!() click to toggle source
# File lib/blade_runner.rb, line 123
def read_arguments!
  if mode = ARGV[0]
    @options[:mode] = mode.to_sym
  end
end
setup_adapter!() click to toggle source
# File lib/blade_runner.rb, line 146
def setup_adapter!
  require "blade_runner/#{config.framework}_adapter"
end
setup_config!() click to toggle source
# File lib/blade_runner.rb, line 129
def setup_config!
  ignore_options = ALLOWED_MODES + [:plugins]

  options = @options.except(ignore_options)
  options[:mode] = DEFAULT_MODE unless ALLOWED_MODES.include?(options[:mode])

  if options_for_mode = @options[options[:mode]]
    options.merge! options_for_mode.except(ignore_options)
  end

  options[:port] ||= DEFAULT_PORT
  options[:load_paths] = Array(options[:load_paths])
  options[:logical_paths] = Array(options[:logical_paths])

  @config = OpenStruct.new(options)
end
setup_plugins!() click to toggle source
# File lib/blade_runner.rb, line 150
def setup_plugins!
  @plugins = OpenStruct.new

  plugin_config = @options[:plugins] || {}

  if plugins_for_mode = (@options[config.mode] || {})[:plugins]
    plugin_config.merge! plugins_for_mode
  end

  plugin_config.each do |name, plugin_config|
    plugins[name] = OpenStruct.new(config: OpenStruct.new(plugin_config))
    require "blade_runner/#{name}_plugin"
  end
end