Class: Ruptr::Formatter

Inherits:
Object
  • Object
show all
Includes:
Sink
Defined in:
lib/ruptr/formatter.rb

Defined Under Namespace

Modules: Colorizing, Verbosity Classes: Plain, TAP, Tabular

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Sink

#begin_case, #begin_group, #begin_plan, #finish_case, #finish_group, #finish_plan, #submit_case, #submit_group, #submit_plan

Class Attribute Details

.formatter_nameObject

Returns the value of attribute formatter_name.



35
36
37
# File 'lib/ruptr/formatter.rb', line 35

def formatter_name
  @formatter_name
end

Class Method Details

.class_from_env(env = ENV) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/ruptr/formatter.rb', line 11

def class_from_env(env = ENV)
  if (s = env['RUPTR_FORMAT'])
    find_formatter(s.to_sym) or fail "unknown formatter: #{s}"
  else
    require_relative 'plain'
    Plain
  end
end

.find_formatter(name) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/ruptr/formatter.rb', line 37

def find_formatter(name)
  traverse = proc do |c|
    return c if c.formatter_name == name
    c.subclasses.each(&traverse)
  end
  traverse.call(self)
  nil
end

.from_env(output, env = ENV, **opts) ⇒ Object



29
30
31
32
33
# File 'lib/ruptr/formatter.rb', line 29

def from_env(output, env = ENV, **opts)
  klass = class_from_env(env)
  opts = opts_from_env(klass, env, **opts)
  klass.new(output, **opts)
end

.opts_from_env(klass, env = ENV, **opts) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ruptr/formatter.rb', line 20

def opts_from_env(klass, env = ENV, **opts)
  if klass.include?(Verbosity)
    if (s = env['RUPTR_VERBOSE'])
      opts[:verbosity] = /\A-?\d+\z/.match?(s) ? s.to_i : 1
    end
  end
  opts
end