Sha256: 93ab913a01bfc8aff8a2c9162bf1e9dce323219a271ba7550c7e9b4216ebcdcb

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

module Foreplay
  class Engine
    class Server
      include Foreplay::Engine::Port
      attr_reader :environment, :mode, :instructions, :server

      def initialize(e, m, i, s)
        @environment  = e
        @mode         = m
        @instructions = i
        @server       = s

        @path = nil
        @host = nil
        @port_details = nil
        @current_port_remote = nil
      end

      def execute
        execute_announce
        foreman
        env

        Foreplay::Engine::Remote.new(server, steps, instructions).__send__ mode
      end

      def execute_announce
        preposition = mode == :deploy ? 'to' : 'for'
        puts "#{mode.capitalize}ing #{name.yellow} #{preposition} #{host.yellow} "\
            "for the #{role.dup.yellow} role in the #{environment.dup.yellow} environment"
      end

      def foreman
        instructions['foreman'] = {} unless instructions.key? 'foreman'

        instructions['foreman'].merge!(
          'app'   => current_service,
          'port'  => current_port,
          'user'  => user,
          'log'   => "$HOME/#{path}/#{current_port}/log"
        )
      end

      def env
        instructions['env'] = {} unless instructions.key? 'env'

        instructions['env'].merge!(
          'HOME'      => '$HOME',
          'SHELL'     => '$SHELL',
          'PATH'      => '$PATH:`which bundle`',
          'GEM_HOME'  => '$HOME/.rvm/gems/`rvm tools identifier`',
          'RAILS_ENV' => environment
        )
      end

      def role
        @role ||= instructions['role']
      end

      def user
        @user ||= instructions['user']
      end

      def path
        return @path if @path

        @path = instructions['path']
        @path.gsub! '%u', user
        @path.gsub! '%a', name
        @path
      end

      def steps
        @steps ||= YAML.load(
          ERB.new(
            File.read(
              "#{File.dirname(__FILE__)}/steps.yml"
            )
          ).result(binding)
        )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreplay-0.13.5 lib/foreplay/engine/server.rb
foreplay-0.13.4 lib/foreplay/engine/server.rb
foreplay-0.13.3 lib/foreplay/engine/server.rb
foreplay-0.13.2 lib/foreplay/engine/server.rb
foreplay-0.13.1 lib/foreplay/engine/server.rb
foreplay-0.13.0 lib/foreplay/engine/server.rb
foreplay-0.11.2 lib/foreplay/engine/server.rb
foreplay-0.11.1 lib/foreplay/engine/server.rb
foreplay-0.11.0 lib/foreplay/engine/server.rb