Class: DeployDir

Inherits:
Dir
  • Object
show all
Defined in:
lib/deploy_dir.rb

Overview

This class extends Dir to add Deploy ad hoc feature for dealing with deploy folders

Could be simply extend Dir class with extra functions but this class meant to be a Deploy System Directory class handler

Author

Jose A Pio ([email protected])

Copyright

Copyright © 2011

License

Distributes under the same terms as Ruby

Class Method Summary collapse

Class Method Details

.rotate_folders(folder, limit) ⇒ Object

Rotate old folders and reduce it number by the limit

Params:

folder

String A valid folder for deploys

limit

Integer Limit the folders left in deploy folder

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/deploy_dir.rb', line 14

def self.rotate_folders(folder , limit)
  raise(ArgumentError, "Invalid directory #{folder}") unless exists?(folder)

  glob(folder.join("*")).select {|file| file =~ /\d+?/ }.tap do |list|
    FileUtils.rm_rf(list.reverse.slice(limit.to_i, list.length)) if list.length > limit.to_i
  end
end