Module: Vanity::Commands

Extended by:
Render
Defined in:
lib/vanity/commands/report.rb,
lib/vanity/commands/list.rb,
lib/vanity/commands/upgrade.rb

Overview

Commands available when running Vanity from the command line (see bin/vanity).

Class Method Summary collapse

Methods included from Render

render, vanity_h, vanity_html_safe, vanity_simple_format

Class Method Details

.listObject

Lists all experiments and metrics.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vanity/commands/list.rb', line 5

def list
  Vanity.playground.experiments.each do |id, experiment|
    puts "experiment :%-.20s (%-.40s)" % [id, experiment.name]
    if experiment.respond_to?(:alternatives)
      experiment.alternatives.each do |alt|
        hash = experiment.fingerprint(alt)
        puts "  %s: %-40.40s  (%s)" % [alt.name, alt.value, hash]
      end
    end
  end
  Vanity.playground.metrics.each do |id, metric|
    puts "metric :%-.20s (%-.40s)" % [id, metric.name]
  end
end

.report(output = nil) ⇒ Object

Generate an HTML report. Outputs to the named file, or stdout with no arguments.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vanity/commands/report.rb', line 50

def report(output = nil)
  html = render(Vanity.template("report"))
  if output
    File.open output, 'w' do |file|
      file.write html
    end
    puts "New report available in #{output}"
  else
    $stdout.write html
  end
end

.upgradeObject

Upgrade to newer version of Vanity (this usually means doing magic in the database)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vanity/commands/upgrade.rb', line 6

def upgrade
  if Vanity.playground.connection.respond_to?(:redis)
    redis = Vanity.playground.connection.redis
    # Upgrade metrics from 1.3 to 1.4
    keys = redis.keys("metrics:*")
    if keys.empty?
      puts "No metrics to upgrade"
    else
      puts "Updating #{keys.map { |name| name.split(":")[1] }.uniq.length} metrics"
      keys.each do |key|
        key << ":value:0" if key[/\d{4}-\d{2}-\d{2}$/] 
        redis.renamenx key, "vanity:#{key}"
      end
    end
    # Upgrade experiments from 1.3 to 1.4
    keys = redis.keys("vanity:1:*")
    if keys.empty?
      puts "No experiments to upgrade"
    else
      puts "Updating #{keys.map { |name| name.split(":")[2] }.uniq.length} experiments"
      keys.each do |key|
        redis.renamenx key, key.gsub(":1:", ":experiments:")
      end
    end
  end
end