Sha256: 9ff0014ec60832a9b9075a763efb3dadb4f0a63019a669e10aa29036e6527fe6

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'erb'
require 'blazing/cli_logging'
require 'grit'

class Blazing::Runner

  include Blazing::CLILogging

  def initialize(config = nil, target = nil)
    if config
      @config = config
      @target = @config.targets.find { |t| t.name.to_s == target } || @config.default_target
    end
  end

  def exec(command)
    command_method = "#{command.gsub(':', '_')}_command"
    raise "Unknown Command: #{command}" unless self.respond_to? command_method
    self.send command_method
  end

  def init_command
    info("Creating an example config file in #{Blazing::DEFAULT_CONFIG_LOCATION}")
    info("Customize it to your needs")

    Dir.mkdir 'config' unless File.exists? 'config'
    configuration_file = ERB.new(File.read("#{Blazing::TEMPLATE_ROOT}/config.erb")).result

    File.open(Blazing::DEFAULT_CONFIG_LOCATION,"wb") do |f|
      f.puts configuration_file
    end
  end

  def setup_git_remotes
    repository = Grit::Repo.new(Dir.pwd)
    @config.targets.each do |target|
      info("Adding new remote #{target.name} pointing to #{target.location}")
      repository.config["remote.#{target.name}.url"] = target.location
    end
  end

  def setup_command
    @target.setup
    update_command
  end

  def update_command
    setup_git_remotes
    @target.apply_hook
  end

  def recipes_run_command
    @config.recipes.each { |recipe| recipe.run(@target.options) }
  end

  def recipes_list_command
    Blazing::Recipe.list.each { |r| puts r.to_s.demodulize.underscore }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blazing-0.2.0 lib/blazing/runner.rb