Sha256: e664a3e2baf7a2b0954ed59decce52ce818187690e97803de8e6ab391c3debe2

Contents?: true

Size: 1.54 KB

Versions: 21

Compression:

Stored size: 1.54 KB

Contents

module Geordi
  class CapistranoConfig

    attr_accessor :root

    def initialize(stage)
      self.stage = stage
      self.root = find_project_root!
      load_deploy_info
    end

    def user(server)
      cap2user = deploy_info[ /^set :user, ['"](.*?)['"]/, 1 ]
      cap2user || deploy_info[ /^server ['"]#{ server }['"],.*user.{1,4}['"](.*?)['"]/, 1 ]
    end

    def servers
      deploy_info.scan(/^server ['"](.*?)['"]/).flatten
    end

    def primary_server
      # Actually, servers may have a :primary property. From Capistrano 3, the
      # first listed server is the primary one by default, which is a good-
      # enough default for us.
      servers.first
    end

    def remote_root
      File.join deploy_info[ /^set :deploy_to, ['"](.*?)['"]/, 1 ], 'current'
    end

    def env
      deploy_info[ /^set :rails_env, ['"](.*?)['"]/, 1 ]
    end

    def shell
      'bash --login'
    end

    private

    attr_accessor :deploy_info, :stage

    def load_deploy_info
      self.deploy_info = File.read(File.join root, 'config/deploy.rb').tap do |info|
        if stage
          info << "\n" << File.read(File.join root, "config/deploy/#{ stage }.rb")
        end
      end
    end

    def find_project_root!
      current = Dir.pwd
      until File.exists?('Capfile')
        Dir.chdir '..'
        raise <<-ERROR if current == Dir.pwd
Could not locate Capfile.

Are you calling me from within a Rails project?
Maybe Capistrano is not installed in this project.
        ERROR

        current = Dir.pwd
      end
      current
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
geordi-1.9.1 lib/geordi/capistrano_config.rb
geordi-1.9.0 lib/geordi/capistrano_config.rb
geordi-1.8.0 lib/geordi/capistrano_config.rb
geordi-1.7.1 lib/geordi/capistrano_config.rb
geordi-1.7.0 lib/geordi/capistrano_config.rb
geordi-1.6.5 lib/geordi/capistrano_config.rb
geordi-1.6.4 lib/geordi/capistrano_config.rb
geordi-1.6.3 lib/geordi/capistrano_config.rb
geordi-1.6.2 lib/geordi/capistrano_config.rb
geordi-1.6.1 lib/geordi/capistrano_config.rb
geordi-1.6.0 lib/geordi/capistrano_config.rb
geordi-1.5.2 lib/geordi/capistrano_config.rb
geordi-1.5.1 lib/geordi/capistrano_config.rb
geordi-1.5.0 lib/geordi/capistrano_config.rb
geordi-1.4.3 lib/geordi/capistrano_config.rb
geordi-1.4.2 lib/geordi/capistrano_config.rb
geordi-1.4.1 lib/geordi/capistrano_config.rb
geordi-1.4.0 lib/geordi/capistrano_config.rb
geordi-1.3.2 lib/geordi/capistrano_config.rb
geordi-1.3.1 lib/geordi/capistrano_config.rb