Module: Polyrun::Hooks::Dsl

Defined in:
lib/polyrun/hooks/dsl.rb

Overview

Ruby DSL for hooks.ruby / hooks.ruby_file in polyrun.yml (see README).

Example file (config/polyrun_hooks.rb):

before(:suite) { |env| puts env["POLYRUN_HOOK_PHASE"] }
after(:each) { |env| }

Blocks receive a hash with string keys (same env as shell hooks).

Defined Under Namespace

Classes: FileContext, Registry

Class Method Summary collapse

Class Method Details

.clear_cache!Object



110
111
112
# File 'lib/polyrun/hooks/dsl.rb', line 110

def clear_cache!
  cache_mu.synchronize { registry_cache.clear }
end

.load_registry(path) ⇒ Registry?

Returns:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/polyrun/hooks/dsl.rb', line 90

def load_registry(path)
  return nil if path.nil? || path.to_s.strip.empty?

  full = File.expand_path(path.to_s, Dir.pwd)
  return nil unless File.file?(full)

  mtime = File.mtime(full)
  cache_mu.synchronize do
    hit = registry_cache[full]
    return hit[:registry] if hit && hit[:mtime] == mtime

    reg = FileContext.new(full).load_file
    registry_cache[full] = {mtime: mtime, registry: reg}
    reg
  end
rescue => e
  Polyrun::Log.warn "polyrun hooks: failed to load #{full}: #{e.class}: #{e.message}"
  nil
end