Sha256: dce8a43df1bf0a37206b30b248ee8f27568ec7b59ec430e0ec4b0249a9b0690d

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module Travis
  class Keychain
    include Deploy::Helper

    attr_reader :app, :shell, :dir

    def initialize(app, shell, dir = '../travis-keychain')
      @app = app
      @shell = shell
      @dir = File.expand_path(dir)
    end

    def fetch
      chdir { pull }
      read
    end

    def source
      @source ||= fetch
    end

    def includes(name)
      include_files[name]
    end

    protected

      def include_files
        @include_files ||= begin
          contents = {}

          chdir do
            Dir['config/includes/*.yml'].each do |path|
              name = File.basename(path).sub(/\.yml$/, '')
              contents[name] = YAML.load(File.read(path))
            end
          end

          contents
        end
      end

      def pull
        error 'There are unstaged changes in your travis-keychain working directory.' unless clean?
        say 'Fetching the keychain ...'
        run 'git pull'
      end

      def read
        File.read(File.join(dir, "config/travis.#{app}.yml")) || ''
      end

      def chdir(&block)
        FileUtils.mkdir_p(dir)
        Dir.chdir(dir, &block)
      end

      def clean?
        `git status`.include?('working directory clean')
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
travis-deploy-0.2.1 lib/travis/keychain.rb
travis-deploy-0.2.0 lib/travis/keychain.rb