Class: Chef::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/chefspec/extensions/chef/resource/freebsd_package.rb,
lib/chefspec/extensions/chef/resource.rb

Defined Under Namespace

Classes: Conditional, FreebsdPackage

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Resource


5
6
7
8
# File 'lib/chefspec/extensions/chef/resource.rb', line 5

def initialize(*args)
  @performed_actions = {}
  old_initialize(*args)
end

Instance Method Details

#old_initializeObject


4
# File 'lib/chefspec/extensions/chef/resource.rb', line 4

alias_method :old_initialize, :initialize

#old_run_actionObject


10
# File 'lib/chefspec/extensions/chef/resource.rb', line 10

alias_method :old_run_action, :run_action

#perform_action(action, options = {}) ⇒ Object


33
34
35
36
# File 'lib/chefspec/extensions/chef/resource.rb', line 33

def perform_action(action, options = {})
  @performed_actions[action.to_sym] ||= {}
  @performed_actions[action.to_sym].merge!(options)
end

#performed_action(action) ⇒ Object


38
39
40
# File 'lib/chefspec/extensions/chef/resource.rb', line 38

def performed_action(action)
  @performed_actions[action.to_sym]
end

#performed_action?(action) ⇒ Boolean


42
43
44
# File 'lib/chefspec/extensions/chef/resource.rb', line 42

def performed_action?(action)
  !!performed_action(action)
end

#performed_actionsObject


46
47
48
# File 'lib/chefspec/extensions/chef/resource.rb', line 46

def performed_actions
  @performed_actions.keys
end

#run_action(action, notification_type = nil, notifying_resource = nil) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chefspec/extensions/chef/resource.rb', line 11

def run_action(action, notification_type = nil, notifying_resource = nil)
  resolve_notification_references
  validate_action(action)

  Chef::Log.info("Processing #{self} action #{action} (#{defined_at})")

  ChefSpec::Coverage.add(self)

  unless should_skip?(action)
    if node.runner.step_into?(self)
      instance_eval { @not_if = []; @only_if = [] }
      old_run_action(action, notification_type, notifying_resource)
    end

    if node.runner.compiling?
      perform_action(action, compile_time: true)
    else
      perform_action(action, converge_time: true)
    end
  end
end