Sha256: 814fcffee0c54d930d85d889b1b1ec70a16ae910439807c43f9837424403722a

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'cymbal'

module Menagerie
  ##
  # Connection object that contains releases
  class Collection
    def initialize(params = {})
      params = Cymbal.symbolize params
      @paths = default_paths.merge(params[:paths] || {})
      @options = default_options.merge(params[:options] || {})
    end

    def releases
      Dir.glob("#{@paths[:releases]}/*").map do |x|
        Release.new path: x
      end
    end

    def create(artifacts)
      rotate
      Release.new artifacts: artifacts, paths: @paths
      reap if @options[:reap]
      link_latest
    end

    private

    def rotate
      existing = releases.reverse.sort
      existing.pop(existing.size - @options[:retention]).each(&:delete)
      existing.each(&:rotate)
    end

    def reap
    end

    def link_latest
      FileUtils.ln_sf releases.sort.first.path, "#{@paths[:latest]}"
    end

    def default_paths
      {
        artifacts: 'artifacts',
        releases: 'releases',
        latest: 'latest'
      }
    end

    def default_options
      {
        retention: 5,
        reap: true
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
menagerie-0.0.1 lib/menagerie/collection.rb