Class: TestProf::EventProf::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/event_prof.rb

Overview

EventProf configuration

Constant Summary collapse

INSTRUMENTERS =

Map of supported instrumenters

{
  active_support: "ActiveSupport"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Configuration

Returns a new instance of Configuration.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/test_prof/event_prof.rb', line 42

def initialize
  @event = ENV["EVENT_PROF"]
  @instrumenter = :active_support
  @top_count = (ENV["EVENT_PROF_TOP"] || 5).to_i
  @per_example = ENV["EVENT_PROF_EXAMPLES"] == "1"
  @rank_by = (ENV["EVENT_PROF_RANK"] || :time).to_sym
  @format = ENV["EVENT_PROF_FORMAT"]
  @stamp = ENV["EVENT_PROF_STAMP"]

  RSpecStamp.config.tags = @stamp if stamp?
end

Instance Attribute Details

#event ⇒ Object

Returns the value of attribute event.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def event
  @event
end

#format ⇒ Object

Returns the value of attribute format.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def format
  @format
end

#instrumenter ⇒ Object

Returns the value of attribute instrumenter.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def instrumenter
  @instrumenter
end

#per_example ⇒ Object

Returns the value of attribute per_example.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def per_example
  @per_example
end

#rank_by ⇒ Object

Returns the value of attribute rank_by.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def rank_by
  @rank_by
end

#top_count ⇒ Object

Returns the value of attribute top_count.



39
40
41
# File 'lib/test_prof/event_prof.rb', line 39

def top_count
  @top_count
end

Instance Method Details

#per_example? ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/test_prof/event_prof.rb', line 58

def per_example?
  per_example == true
end

#printer ⇒ Object



62
63
64
65
66
67
# File 'lib/test_prof/event_prof.rb', line 62

def printer
  case format.to_s
  when "json" then Printers::Json
  else Printers::Simple
  end
end

#resolve_instrumenter ⇒ Object

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
# File 'lib/test_prof/event_prof.rb', line 69

def resolve_instrumenter
  return instrumenter if instrumenter.is_a?(Module)

  raise ArgumentError, "Unknown instrumenter: #{instrumenter}" unless
    INSTRUMENTERS.key?(instrumenter)

  Instrumentations.const_get(INSTRUMENTERS[instrumenter])
end

#stamp? ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/test_prof/event_prof.rb', line 54

def stamp?
  !@stamp.nil?
end