Method: Chef::Provider.use

Defined in:
lib/chef/provider.rb

.use(partial) ⇒ Object

Use a partial code fragment. This can be used for code sharing between multiple resources.

Do not wrap the code fragment in a class or module. It also does not support the use of super to subclass any methods defined in the fragment, the methods will just be overwritten.

Parameters:

  • partial (String)

    the code fragment to eval against the class



112
113
114
115
116
117
# File 'lib/chef/provider.rb', line 112

def self.use(partial)
  dirname = ::File.dirname(partial)
  basename = ::File.basename(partial, ".rb")
  basename = basename[1..] if basename.start_with?("_")
  class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.path)))
end