Sha256: 4e76c7ff571d33f5d5ff79d855bf38f92a61ad923f3819a77e5180603fc495e2
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Expire # Create playground with example data class Playground STEP_WIDTHS = { 'hourly' => 'hour', 'daily' => 'day', 'weekly' => 'week', 'monthly' => 'month', 'yearly' => 'year' }.freeze def self.create(base) new(base).create end def initialize(base) @base = base @backups_dir = Pathname.new("#{base}/backups") @options = { hourly: 42, daily: 15, weekly: 15, monthly: 25, yearly: 5 } end attr_reader :backups_dir, :base, :options 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 def mkbackup(datetime) backup_name = datetime.to_s.sub(/:\d\d[+-]\d\d:\d\d\z/, '') FileUtils.mkdir_p("#{backups_dir}/#{backup_name}") end def raise_if_backups_dir_exists return unless FileTest.exist?(backups_dir) raise( PathAlreadyExistsError, "Will not create playground in existing path #{backups_dir}" ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
expire-0.2.0 | lib/expire/playground.rb |