Sha256: fb7057d301e376a5f9b071d941a7adde9e44a7a9f836d2fbaf4789d90d7fdb36

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

module Blazing
  class Target

    attr_accessor :name, :recipes

    @@configuration_options = [:deploy_to, :host, :user, :path, :default]

    def initialize(name, options = {})
      @name = name.to_s
      @@configuration_options.each do |option|
        instance_variable_set("@#{option}", options[option])
        self.class.send(:attr_accessor, option)
      end

      # If the :deploy_to option is given, user, host and path are overriden
      unless deploy_to.blank? 
        @host = deploy_to.scan(/@(.*):/).join
        @user = deploy_to.scan(/(.*)@/).join
        @path = deploy_to.scan(/:(.*)/).join
      end

      # Raise an error if one of the required options is still empty
      [:host, :user, :path].each do |option|
        raise "#{option} can't be blank!" if instance_variable_get("@#{option}").blank?
      end
    end

    def setup
      clone_command = "if [ -e #{path} ]; then \
                     echo 'directory exists already'; else \
                     git clone #{config.repository} #{path} && cd #{path} && git config receive.denyCurrentBranch ignore; fi"

      system "ssh #{user}@#{host} '#{clone_command}'"
      system "git remote add #{name} #{user}@#{host}:#{path}"

      Blazing::CLI::Hook.new([name]).generate #.generate(target.name)
      system "scp /tmp/post-receive #{user}@#{host}:#{path}/.git/hooks/post-receive"
      system "ssh #{user}@#{host} 'chmod +x #{path}/.git/hooks/post-receive'"
    end

    def deploy
      system "git push #{name}"
    end

    def config
      Blazing::Config.load
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blazing-0.0.6 lib/blazing/target.rb
blazing-0.0.5 lib/blazing/target.rb