Class: Cheffish::BasicChefClient

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Chef::DSL::Recipe
Defined in:
lib/cheffish/basic_chef_client.rb

Defined Under Namespace

Classes: BasicChefClientEvents, ProviderEventForwarder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chef::DSL::Recipe

#with_chef_data_bag, #with_chef_data_bag_item_encryption, #with_chef_environment, #with_chef_local_server, #with_chef_server

Constructor Details

#initialize(node = nil, events = nil) ⇒ BasicChefClient

Returns a new instance of BasicChefClient.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cheffish/basic_chef_client.rb', line 14

def initialize(node = nil, events = nil)
  if !node
    node = Chef::Node.new
    node.name 'basic_chef_client'
    node.automatic[:platform] = 'basic_chef_client'
    node.automatic[:platform_version] = Cheffish::VERSION
  end

  @event_catcher = BasicChefClientEvents.new
  dispatcher = Chef::EventDispatch::Dispatcher.new(@event_catcher)
  dispatcher.register(events) if events
  @run_context = Chef::RunContext.new(node, {}, dispatcher)
  @updated = []
  @cookbook_name = 'basic_chef_client'
end

Instance Attribute Details

#cookbook_nameObject

Returns the value of attribute cookbook_name.



34
35
36
# File 'lib/cheffish/basic_chef_client.rb', line 34

def cookbook_name
  @cookbook_name
end

#recipe_nameObject

Returns the value of attribute recipe_name.



35
36
37
# File 'lib/cheffish/basic_chef_client.rb', line 35

def recipe_name
  @recipe_name
end

#run_contextObject (readonly)

Stuff recipes need



33
34
35
# File 'lib/cheffish/basic_chef_client.rb', line 33

def run_context
  @run_context
end

Class Method Details

.converge_block(node = nil, events = nil, &block) ⇒ Object



63
64
65
66
67
68
# File 'lib/cheffish/basic_chef_client.rb', line 63

def self.converge_block(node = nil, events = nil, &block)
  client = BasicChefClient.new(node, events)
  client.load_block(&block)
  client.converge
  client.updated?
end

.inline_resource(provider, provider_action, &block) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/cheffish/basic_chef_client.rb', line 55

def self.inline_resource(provider, provider_action, &block)
  events = ProviderEventForwarder.new(provider, provider_action)
  client = BasicChefClient.new(provider.node, events)
  client.load_block(&block)
  client.converge
  client.updated?
end

Instance Method Details

#convergeObject



43
44
45
# File 'lib/cheffish/basic_chef_client.rb', line 43

def converge
  Chef::Runner.new(self).converge
end

#load_block(&block) ⇒ Object



38
39
40
41
# File 'lib/cheffish/basic_chef_client.rb', line 38

def load_block(&block)
  @recipe_name = 'block'
  instance_eval(&block)
end

#updated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cheffish/basic_chef_client.rb', line 51

def updated?
  @event_catcher.updates.size > 0
end

#updatesObject



47
48
49
# File 'lib/cheffish/basic_chef_client.rb', line 47

def updates
  @event_catcher.updates
end