Sha256: c100cfb83b7780d3e756d4e957b709c7df812c762772b6a2cca1be0963360383

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 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 == target.to_s } || @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_local_command
    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_remote_command
    @config.default_target.setup
  end

  def update_command
    @config.default_target.update
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blazing-0.1.0.alpha3 lib/blazing/runner.rb