Class: Evilution::Reporter::Suggestion::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/reporter/suggestion/registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



36
37
38
39
# File 'lib/evilution/reporter/suggestion/registry.rb', line 36

def initialize
  @generic = {}
  @concrete = Hash.new { |h, k| h[k] = {} }
end

Class Method Details

.defaultObject

rubocop:enable Style/OneClassPerFile



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/evilution/reporter/suggestion/registry.rb', line 11

def self.default
  return @default if @default

  require_relative "templates/generic"
  require_relative "templates/rspec"
  require_relative "templates/minitest"

  registry = new
  Evilution::Reporter::Suggestion::Templates::Generic::GENERIC_ENTRIES.each do |op, text|
    registry.register_generic(op, text)
  end
  Evilution::Reporter::Suggestion::Templates::Rspec::RSPEC_ENTRIES.each do |op, blk|
    registry.register_concrete(op, integration: :rspec, block: blk)
  end
  Evilution::Reporter::Suggestion::Templates::Minitest::MINITEST_ENTRIES.each do |op, blk|
    registry.register_concrete(op, integration: :minitest, block: blk)
  end

  @default = registry
end

.reset!Object



32
33
34
# File 'lib/evilution/reporter/suggestion/registry.rb', line 32

def self.reset!
  @default = nil
end

Instance Method Details

#concrete(operator_name, integration:) ⇒ Object



55
56
57
# File 'lib/evilution/reporter/suggestion/registry.rb', line 55

def concrete(operator_name, integration:)
  @concrete.fetch(integration, {})[operator_name]
end

#each_generic_operatorObject



59
60
61
62
63
# File 'lib/evilution/reporter/suggestion/registry.rb', line 59

def each_generic_operator(&)
  return @generic.each_key unless block_given?

  @generic.each_key(&)
end

#generic(operator_name) ⇒ Object



51
52
53
# File 'lib/evilution/reporter/suggestion/registry.rb', line 51

def generic(operator_name)
  @generic[operator_name]
end

#register_concrete(operator_name, integration:, block:) ⇒ Object



46
47
48
49
# File 'lib/evilution/reporter/suggestion/registry.rb', line 46

def register_concrete(operator_name, integration:, block:)
  @concrete[integration][operator_name] = block
  self
end

#register_generic(operator_name, text) ⇒ Object



41
42
43
44
# File 'lib/evilution/reporter/suggestion/registry.rb', line 41

def register_generic(operator_name, text)
  @generic[operator_name] = text
  self
end