Class: Kafo::HookContext

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/hook_context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kafo) ⇒ HookContext

Returns a new instance of HookContext.



16
17
18
# File 'lib/kafo/hook_context.rb', line 16

def initialize(kafo)
  @kafo = kafo
end

Instance Attribute Details

#kafoObject (readonly)

Returns the value of attribute kafo.



3
4
5
# File 'lib/kafo/hook_context.rb', line 3

def kafo
  @kafo
end

Class Method Details

.execute(kafo, &hook) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/kafo/hook_context.rb', line 5

def self.execute(kafo, &hook)
  # TODO can be removed in 0.6, is DEPRECATED since 0.5
  # instance_exec can be later changed to instance eval when people stop using |kafo| in their hooks
  # and rely only on hook context DSL
  if hook.arity > 0
    kafo.logger.warn "Hook '#{name}' is using block with arguments which is DEPRECATED, access to kafo instance is " +
                    "provided by hook DSL, please remove |kafo| from your hook block"
  end
  new(kafo).instance_exec(kafo, &hook)
end

Instance Method Details

#app_option(*args) ⇒ Object

if you want to add new app_option be sure to do as soon as possible (usually boot hook) otherwise it may be to late (e.g. when displaying help) examples:

app_option '--log-level', 'LEVEL', 'Log level for log file output', :default => config.app[:log_level]:
app_option ['-n', '--noop'], :flag, 'Run puppet in noop mode?', :default => false


33
34
35
# File 'lib/kafo/hook_context.rb', line 33

def app_option(*args)
  self.kafo.class.app_option *args
end

#app_value(option) ⇒ Object

examples:

app_value(:log_level)

note the dash to underscore convention



40
41
42
# File 'lib/kafo/hook_context.rb', line 40

def app_value(option)
  self.kafo.config.app[option.to_sym]
end

#loggerObject

some of hooks won’t print any message because logger is not yet configured configuration of logger depends on application configration (log level etc.) examples:

logger.warn "this combindation of parameters is untested"


24
25
26
# File 'lib/kafo/hook_context.rb', line 24

def logger
  self.kafo.logger
end

#param(module_name, parameter_name) ⇒ Object

examples:

param('foreman', 'interface').value = 'eth0'
param('foreman', 'interface').value = app_option('bind_on_interface')


47
48
49
# File 'lib/kafo/hook_context.rb', line 47

def param(module_name, parameter_name)
  self.kafo.param(module_name, parameter_name)
end