Sha256: 1854a9c849313257762f6649d53853d23bc70ca2505a4e4dfe9ad3fee10b4f1e

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

require 'erb'
require 'grit'

class Blazing::Runner

  include Blazing::Logger

  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

4 entries across 4 versions & 1 rubygems

Version Path
blazing-0.2.7 lib/blazing/runner.rb
blazing-0.2.6 lib/blazing/runner.rb
blazing-0.2.5 lib/blazing/runner.rb
blazing-0.2.4 lib/blazing/runner.rb