Class: Chef::Provider

Inherits:
Object
  • Object
show all
Extended by:
Mixin::ConvertToClassName
Includes:
Mixin::RecipeDefinitionDSLCore
Defined in:
lib/chef/provider.rb,
lib/chef/provider/env.rb,
lib/chef/provider/git.rb,
lib/chef/provider/log.rb,
lib/chef/provider/cron.rb,
lib/chef/provider/file.rb,
lib/chef/provider/link.rb,
lib/chef/provider/ohai.rb,
lib/chef/provider/user.rb,
lib/chef/provider/group.rb,
lib/chef/provider/mdadm.rb,
lib/chef/provider/mount.rb,
lib/chef/provider/deploy.rb,
lib/chef/provider/script.rb,
lib/chef/provider/execute.rb,
lib/chef/provider/package.rb,
lib/chef/provider/service.rb,
lib/chef/provider/user/pw.rb,
lib/chef/provider/erl_call.rb,
lib/chef/provider/group/pw.rb,
lib/chef/provider/ifconfig.rb,
lib/chef/provider/template.rb,
lib/chef/provider/directory.rb,
lib/chef/provider/user/dscl.rb,
lib/chef/provider/breakpoint.rb,
lib/chef/provider/group/dscl.rb,
lib/chef/provider/ruby_block.rb,
lib/chef/provider/subversion.rb,
lib/chef/provider/env/windows.rb,
lib/chef/provider/mount/mount.rb,
lib/chef/provider/package/apt.rb,
lib/chef/provider/package/rpm.rb,
lib/chef/provider/package/yum.rb,
lib/chef/provider/remote_file.rb,
lib/chef/provider/cron/solaris.rb,
lib/chef/provider/http_request.rb,
lib/chef/provider/package/dpkg.rb,
lib/chef/provider/service/init.rb,
lib/chef/provider/user/useradd.rb,
lib/chef/provider/user/windows.rb,
lib/chef/provider/cookbook_file.rb,
lib/chef/provider/group/gpasswd.rb,
lib/chef/provider/group/usermod.rb,
lib/chef/provider/group/windows.rb,
lib/chef/provider/mount/windows.rb,
lib/chef/provider/group/groupadd.rb,
lib/chef/provider/package/pacman.rb,
lib/chef/provider/package/zypper.rb,
lib/chef/provider/service/debian.rb,
lib/chef/provider/service/redhat.rb,
lib/chef/provider/service/simple.rb,
lib/chef/provider/deploy/revision.rb,
lib/chef/provider/package/freebsd.rb,
lib/chef/provider/package/portage.rb,
lib/chef/provider/package/solaris.rb,
lib/chef/provider/service/freebsd.rb,
lib/chef/provider/service/solaris.rb,
lib/chef/provider/service/upstart.rb,
lib/chef/provider/package/macports.rb,
lib/chef/provider/package/rubygems.rb,
lib/chef/provider/remote_directory.rb,
lib/chef/provider/deploy/timestamped.rb,
lib/chef/provider/package/easy_install.rb

Defined Under Namespace

Classes: Breakpoint, CookbookFile, Cron, Deploy, Directory, Env, ErlCall, Execute, File, Git, Group, HttpRequest, Ifconfig, Link, Log, Mdadm, Mount, Ohai, Package, RemoteDirectory, RemoteFile, Route, RubyBlock, Script, Service, Subversion, Template, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ConvertToClassName

convert_to_class_name, convert_to_snake_case, filename_to_qualified_string, snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

#initialize(new_resource, run_context) ⇒ Provider

Returns a new instance of Provider.



31
32
33
34
35
# File 'lib/chef/provider.rb', line 31

def initialize(new_resource, run_context)
  @new_resource = new_resource
  @current_resource = nil
  @run_context = run_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Attribute Details

#current_resourceObject

Returns the value of attribute current_resource.



29
30
31
# File 'lib/chef/provider.rb', line 29

def current_resource
  @current_resource
end

#new_resourceObject

Returns the value of attribute new_resource.



29
30
31
# File 'lib/chef/provider.rb', line 29

def new_resource
  @new_resource
end

#run_contextObject

Returns the value of attribute run_context.



29
30
31
# File 'lib/chef/provider.rb', line 29

def run_context
  @run_context
end

Class Method Details

.build_from_file(cookbook_name, filename) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/chef/provider.rb', line 84

def build_from_file(cookbook_name, filename)
  pname = filename_to_qualified_string(cookbook_name, filename)
  
  # Add log entry if we override an existing light-weight provider.
  class_name = convert_to_class_name(pname)
  overriding = Chef::Provider.const_defined?(class_name)
  Chef::Log.info("#{class_name} light-weight provider already initialized -- overriding!") if overriding
  
  new_provider_class = Class.new self do |cls|
    
    def load_current_resource
      # silence Chef::Exceptions::Override exception
    end
    
    class << cls
      include Chef::Mixin::FromFile
      
      # setup DSL's shortcut methods
      def action(name, &block)
        define_method("action_#{name.to_s}") do
          instance_eval(&block)
        end
      end
    end
    
    # load provider definition from file
    cls.class_from_file(filename)
  end
  
  # register new class as a Chef::Provider
  pname = filename_to_qualified_string(cookbook_name, filename)
  class_name = convert_to_class_name(pname)
  Chef::Provider.const_set(class_name, new_provider_class)
  Chef::Log.debug("Loaded contents of #{filename} into a provider named #{pname} defined in Chef::Provider::#{class_name}")
  
  new_provider_class
end

Instance Method Details

#action_nothingObject



54
55
56
57
# File 'lib/chef/provider.rb', line 54

def action_nothing
  Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
  true
end

#cookbook_nameObject



46
47
48
# File 'lib/chef/provider.rb', line 46

def cookbook_name
  new_resource.cookbook_name
end

#load_current_resourceObject



50
51
52
# File 'lib/chef/provider.rb', line 50

def load_current_resource
  raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
end

#nodeObject



37
38
39
# File 'lib/chef/provider.rb', line 37

def node
  run_context && run_context.node
end

#resource_collectionObject

Used by providers supporting embedded recipes



42
43
44
# File 'lib/chef/provider.rb', line 42

def resource_collection
  run_context && run_context.resource_collection
end