lib/menagerie/collection.rb in menagerie-0.1.3 vs lib/menagerie/collection.rb in menagerie-1.0.0

- old
+ new

@@ -3,32 +3,37 @@ module Menagerie ## # Connection object that contains releases class Collection - def initialize(params = nil) + def initialize(params = {}) params = Cymbal.symbolize(params || {}) @paths = default_paths.merge(params[:paths] || {}) @options = default_options.merge(params[:options] || {}) + @logger = Menagerie.get_logger(@options[:verbosity]) end def releases Dir.glob("#{@paths[:releases]}/*").map do |x| - Release.new path: x, paths: @paths - end + Release.new path: x, paths: @paths, logger: @logger + end.sort end def orphans keepers = releases.map(&:artifacts).flatten.map(&:path).uniq Dir.glob("#{@paths[:artifacts]}/*/*").reject do |artifact| keepers.include? artifact end end - def create(artifacts) + def add_release(artifacts) rotate - Release.new artifacts: Cymbal.symbolize(artifacts), paths: @paths + Release.new( + artifacts: Cymbal.symbolize(artifacts), + paths: @paths, + logger: @logger + ) reap if @options[:reap] link_latest end private @@ -39,16 +44,20 @@ existing.each(&:delete) keepers.each(&:rotate) end def reap - orphans.each { |orphan| FileUtils.rm_f orphan } + orphans.each do |orphan| + @logger.info "Reaping orphan: #{orphan}" + FileUtils.rm_f orphan + end end def link_latest FileUtils.rm_f @paths[:latest] FileUtils.ln_sf releases.sort.first.path, @paths[:latest] + @logger.debug "Linked latest release to #{@paths[:latest]}" end def default_paths { artifacts: 'artifacts', @@ -58,10 +67,11 @@ end def default_options { retention: 5, - reap: true + reap: true, + verbose: true } end end end