Class: Expire::Playground

Inherits:
Object
  • Object
show all
Defined in:
lib/expire/playground.rb

Overview

Create playground with example data

Constant Summary collapse

STEP_WIDTHS =
{
  "hourly" => "hour",
  "daily" => "day",
  "weekly" => "week",
  "monthly" => "month",
  "yearly" => "year"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Playground

Returns a new instance of Playground.



18
19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#backups_dirObject (readonly)

Returns the value of attribute backups_dir.



31
32
33
# File 'lib/expire/playground.rb', line 31

def backups_dir
  @backups_dir
end

#baseObject (readonly)

Returns the value of attribute base.



31
32
33
# File 'lib/expire/playground.rb', line 31

def base
  @base
end

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/expire/playground.rb', line 31

def options
  @options
end

Class Method Details

.create(base) ⇒ Object



14
15
16
# File 'lib/expire/playground.rb', line 14

def self.create(base)
  new(base).create
end

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/expire/playground.rb', line 33

def create
  raise_if_backups_dir_exists

  oldest_backup = Time.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