class Expire::Playground

Create playground with example data

Constants

STEP_WIDTHS

Attributes

backups_dir[R]
base[R]
options[R]

Public Class Methods

create(base) click to toggle source
# File lib/expire/playground.rb, line 14
def self.create(base)
  new(base).create
end
new(base) click to toggle source
# File lib/expire/playground.rb, line 18
def initialize(base)
  @base        = base
  @backups_dir = Pathname.new("#{base}/backups")

  @options = {
    hourly:  42,
    daily:   15,
    weekly:  15,
    monthly: 25,
    yearly:  5
  }
end

Public Instance Methods

create() click to toggle source
# File lib/expire/playground.rb, line 33
def create
  raise_if_backups_dir_exists

  oldest_backup = DateTime.now

  STEP_WIDTHS.each do |adjective, noun|
    options[adjective.to_sym].times do
      oldest_backup = oldest_backup.ago(1.send(noun))
      mkbackup(oldest_backup)
    end
  end
end

Private Instance Methods

mkbackup(datetime) click to toggle source
# File lib/expire/playground.rb, line 48
def mkbackup(datetime)
  backup_name = datetime.to_s.sub(/:\d\d[+-]\d\d:\d\d\z/, '')
  FileUtils.mkdir_p("#{backups_dir}/#{backup_name}")
end
raise_if_backups_dir_exists() click to toggle source
# File lib/expire/playground.rb, line 53
def raise_if_backups_dir_exists
  return unless FileTest.exist?(backups_dir)

  raise(
    PathAlreadyExistsError,
    "Will not create playground in existing path #{backups_dir}"
  )
end