Sha256: dc9d083a87ccf79d30a19ecd96a1307b4a32f9b60082258c9887673075f3e65d

Contents?: true

Size: 770 Bytes

Versions: 49

Compression:

Stored size: 770 Bytes

Contents

module EbDeployer
  class VersionCleaner
    def initialize(app, number_to_keep)
      @app = app
      @number_to_keep = number_to_keep
    end

    def clean(version_prefix = "")
      if @number_to_keep > 0
        versions_to_remove = versions_to_clean(version_prefix)
        @app.remove(versions_to_remove, true)
      end
    end

    private
    def versions_to_clean(version_prefix = "")
      all_versions = @app.versions.select do |apv|
        apv[:version].start_with?(version_prefix)
      end

      all_versions.sort! { |x, y| y[:date_updated] <=> x[:date_updated] }
      versions_to_keep = all_versions.slice!(range_to_keep)
      all_versions.map { |apv| apv[:version] }
    end

    def range_to_keep
      (0..(@number_to_keep-1))
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
eb_deployer-0.3.8 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.7 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.6 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.5 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.4 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.3 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.2 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.1 lib/eb_deployer/version_cleaner.rb
eb_deployer-0.3.0 lib/eb_deployer/version_cleaner.rb