Class: Capybara::Screenshot::Pruner

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara-screenshot/pruner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy) ⇒ Pruner

Returns a new instance of Pruner.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/capybara-screenshot/pruner.rb', line 6

def initialize(strategy)
  @strategy = strategy

  @strategy_proc = case strategy
  when :keep_all
    lambda { }
  when :keep_last_run
    lambda { prune_with_last_run_strategy }
  when Hash
    raise ArgumentError, ":keep key is required" unless strategy[:keep]
    raise ArgumentError, ":keep must be a Integer" unless strategy[:keep].kind_of?(Integer)
    raise ArgumentError, ":keep value must be number greater than zero" unless strategy[:keep].to_i > 0
    lambda { prune_with_numeric_strategy(strategy[:keep].to_i) }
  else
    fail "Invalid prune strategy #{strategy}. `:keep_all`or `{ keep: 10 }` are valid examples."
  end
end

Instance Attribute Details

#strategyObject (readonly)

Returns the value of attribute strategy.



4
5
6
# File 'lib/capybara-screenshot/pruner.rb', line 4

def strategy
  @strategy
end

Instance Method Details

#prune_old_screenshotsObject



24
25
26
# File 'lib/capybara-screenshot/pruner.rb', line 24

def prune_old_screenshots
  strategy_proc.call
end