Sha256: 04409e4c4af229526a892ddb41b1a79606b280f36ad2b8c99732d7ef4c3786c3

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

require 'phobos/cli/runner'

module Phobos
  module CLI
    class Start
      def initialize(options)
        @config_file = File.expand_path(options[:config])
        @boot_file = File.expand_path(options[:boot])
      end

      def execute
        validate_config_file!
        Phobos.configure(config_file)
        load_boot_file
        validate_listeners!

        Phobos::CLI::Runner.new.run!
      end

      private

      attr_reader :config_file, :boot_file

      def validate_config_file!
        unless File.exist?(config_file)
          Phobos::CLI.logger.error { Hash(message: "Config file not found (#{config_file})") }
          exit(1)
        end
      end

      def validate_listeners!
        Phobos.config.listeners.collect(&:handler).each do |handler_class|
          begin
            handler_class.constantize
          rescue NameError
            Phobos::CLI.logger.error { Hash(message: "Handler '#{handler_class}' not defined") }
            exit(1)
          end
        end
      end

      def load_boot_file
        load(boot_file) if File.exist?(boot_file)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
phobos-1.5.0 lib/phobos/cli/start.rb
phobos-1.4.2 lib/phobos/cli/start.rb
phobos-1.4.1 lib/phobos/cli/start.rb
phobos-1.4.0 lib/phobos/cli/start.rb
phobos-1.3.0 lib/phobos/cli/start.rb
phobos-1.2.1 lib/phobos/cli/start.rb
phobos-1.2.0 lib/phobos/cli/start.rb
phobos-1.1.0 lib/phobos/cli/start.rb
phobos-1.0.0 lib/phobos/cli/start.rb