Class: Chef::Provider

Inherits:
Object show all
Extended by:
Mixin::ConvertToClassName
Includes:
Mixin::EnforceOwnershipAndPermissions, 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/group/aix.rb,
lib/chef/provider/user/dscl.rb,
lib/chef/provider/breakpoint.rb,
lib/chef/provider/group/dscl.rb,
lib/chef/provider/group/suse.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/macosx.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/smartos.rb,
lib/chef/provider/package/solaris.rb,
lib/chef/provider/service/freebsd.rb,
lib/chef/provider/service/insserv.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/service/invokercd.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::EnforceOwnershipAndPermissions

#enforce_ownership_and_permissions

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

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

Constructor Details

#initialize(new_resource, run_context) ⇒ Provider

Returns a new instance of Provider.



33
34
35
36
37
# File 'lib/chef/provider.rb', line 33

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.



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

def current_resource
  @current_resource
end

#new_resourceObject

Returns the value of attribute new_resource.



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

def new_resource
  @new_resource
end

#run_contextObject

Returns the value of attribute run_context.



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

def run_context
  @run_context
end

Class Method Details

.build_from_file(cookbook_name, filename, run_context) ⇒ Object



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
121
122
# File 'lib/chef/provider.rb', line 86

def build_from_file(cookbook_name, filename, run_context)
  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



56
57
58
59
# File 'lib/chef/provider.rb', line 56

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

#cookbook_nameObject



48
49
50
# File 'lib/chef/provider.rb', line 48

def cookbook_name
  new_resource.cookbook_name
end

#load_current_resourceObject



52
53
54
# File 'lib/chef/provider.rb', line 52

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

#nodeObject



39
40
41
# File 'lib/chef/provider.rb', line 39

def node
  run_context && run_context.node
end

#resource_collectionObject

Used by providers supporting embedded recipes



44
45
46
# File 'lib/chef/provider.rb', line 44

def resource_collection
  run_context && run_context.resource_collection
end