Sha256: 381ac9908b872c3931623717eb5ca4232efbaf958127794eed6e22f8cf38cc46

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'erb'
require 'grit'

class Blazing::Runner

  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
    logger.info "Creating an example config file in #{Blazing::DEFAULT_CONFIG_LOCATION}"
    logger.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|
      logger.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

3 entries across 3 versions & 1 rubygems

Version Path
blazing-0.2.3 lib/blazing/runner.rb
blazing-0.2.2 lib/blazing/runner.rb
blazing-0.2.1 lib/blazing/runner.rb