Class: Ufo::Hooks::Builder
- Inherits:
-
Object
- Object
- Ufo::Hooks::Builder
show all
- Extended by:
- Memoist
- Includes:
- DslEvaluator, Dsl, Utils::Logging
- Defined in:
- lib/ufo/hooks/builder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#logger
Methods included from Dsl
#after, #before, #each_hook
Constructor Details
#initialize(options = {}) ⇒ Builder
Returns a new instance of Builder.
9
10
11
12
13
14
15
|
# File 'lib/ufo/hooks/builder.rb', line 9
def initialize(options={})
@options = options
@file = options[:file] @dsl_file = "#{Ufo.root}/.ufo/config/hooks/#{@file}"
@name = options[:name].to_s
@hooks = {before: {}, after: {}}
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/ufo/hooks/builder.rb', line 8
def name
@name
end
|
Instance Method Details
#build ⇒ Object
17
18
19
20
|
# File 'lib/ufo/hooks/builder.rb', line 17
def build
evaluate_file(@dsl_file)
@hooks.deep_stringify_keys!
end
|
#run?(hook) ⇒ Boolean
47
48
49
|
# File 'lib/ufo/hooks/builder.rb', line 47
def run?(hook)
!!hook["execute"]
end
|
#run_each_hook(type) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/ufo/hooks/builder.rb', line 31
def run_each_hook(type)
hooks = @hooks.dig(type, @name) || []
hooks.each do |hook|
run_hook(type, hook)
end
end
|
#run_hook(type, hook) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/ufo/hooks/builder.rb', line 38
def run_hook(type, hook)
return unless run?(hook)
id = "#{type} #{@name}"
label = " label: #{hook["label"]}" if hook["label"]
logger.info "Hook: Running #{id} hook#{label}".color(:cyan) if Ufo.config.hooks.show
Runner.new(hook).run
end
|
#run_hooks ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/ufo/hooks/builder.rb', line 23
def run_hooks
build
run_each_hook("before")
out = yield if block_given?
run_each_hook("after")
out
end
|