Class: Mutant::Hooks Private

Inherits:
Object
  • Object
show all
Includes:
Unparser::Adamantium
Defined in:
lib/mutant/hooks.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Builder, UnknownHook

Constant Summary collapse

DEFAULTS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[
  env_infection_post
  env_infection_pre
  mutation_insert_post
  mutation_insert_pre
  mutation_worker_process_start
  setup_integration_post
  setup_integration_pre
  test_worker_process_start
].product([EMPTY_ARRAY]).to_h.transform_values(&:freeze).freeze
MESSAGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'Unknown hook %s'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assert_name(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
# File 'lib/mutant/hooks.rb', line 24

def self.assert_name(name)
  fail UnknownHook, MESSAGE % name.inspect unless DEFAULTS.key?(name)
  self
end

.emptyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/mutant/hooks.rb', line 29

def self.empty
  new(map: DEFAULTS)
end

.load_config(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Security/Eval



75
76
77
78
79
# File 'lib/mutant/hooks.rb', line 75

def self.load_config(config)
  config.hooks.reduce(empty) do |current, path|
    current.merge(load_pathname(path))
  end
end

.load_pathname(pathname) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Security/Eval



66
67
68
69
70
71
72
# File 'lib/mutant/hooks.rb', line 66

def self.load_pathname(pathname)
  hooks = Builder.new

  binding.eval(pathname.read, pathname.to_s)

  hooks.to_hooks
end

Instance Method Details

#merge(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
# File 'lib/mutant/hooks.rb', line 33

def merge(other)
  self.class.new(
    map: other.map.merge(map) { |_key, new, old| (old + new).freeze }.freeze
  )
end

#run(name, **payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
42
43
44
45
# File 'lib/mutant/hooks.rb', line 39

def run(name, **payload)
  Hooks.assert_name(name)

  map.fetch(name).each { |block| block.call(**payload) }

  self
end