Class: StartupTime::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/startup_time/registry.rb

Overview

StartupTime::Registry - an interface to the tests configured in resources/tests.yaml

Constant Summary collapse

TEST_DATA =

the path to the test configuration file

File.join(__dir__, '../../resources/tests.yaml')
GROUPS =

map each group (e.g. “jvm”) to an array of its member IDs (e.g. [“java”, “kotlin”, “scala”])

Hash.new { |h, k| h[k] = [] }.with_indifferent_access
TESTS =

the top-level hash in tests.yaml. keys are test IDs (e.g. “ruby”); values are test specs

YAML.safe_load(File.read(TEST_DATA)).with_indifferent_access

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



49
50
51
52
# File 'lib/startup_time/registry.rb', line 49

def initialize
  @omit = Set.new
  @only = Set.new
end

Class Method Details

.ids_to_groups(format: :ascii) ⇒ Object

a hash which maps test IDs (e.g. “scala”) to their corresponding group names (e.g. [“compiled”, “jvm”, “slow”])



39
40
41
42
43
44
45
46
47
# File 'lib/startup_time/registry.rb', line 39

def self.ids_to_groups(format: :ascii)
  if format == :json
    TESTS.entries.each_with_object({}) do |(id, test), target|
      target[id] = test[:groups].sort
    end
  else # ASCII
    TESTS.entries.map { |id, test| [id, test[:groups].sort.join(', ')] }
  end
end

Instance Method Details

#omit(id) ⇒ Object

add the specified test(s) to the set of disabled tests



55
56
57
# File 'lib/startup_time/registry.rb', line 55

def omit(id)
  @omit.merge(ids_for(id))
end

#only(id) ⇒ Object

add the specified test(s) to the set of enabled tests



60
61
62
# File 'lib/startup_time/registry.rb', line 60

def only(id)
  @only.merge(ids_for(id))
end

#selected_testsObject

the subset of candidate tests which satisfy the ‘only` and `omit` criteria



65
66
67
68
69
# File 'lib/startup_time/registry.rb', line 65

def selected_tests
  only = !@only.empty? ? @only : TESTS.keys.to_set
  test_ids = (only - @omit).to_a
  TESTS.slice(*test_ids)
end