Class: Puppet::Plugins

Inherits:
Object show all
Defined in:
lib/vendor/puppet/util/plugins.rb

Constant Summary collapse

Paths =

Where we might find plugin initialization code

[]
Loaded =

Code we have found (one-to-one with paths once searched)

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Plugins

Returns a new instance of Plugins.



70
71
72
73
74
75
76
77
78
79
# File 'lib/vendor/puppet/util/plugins.rb', line 70

def initialize(path)
  @name = @path = path
  class << self
    private
    def define_hooks
      eval File.read(path),nil,path,1
    end
  end
  define_hooks
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



69
70
71
# File 'lib/vendor/puppet/util/plugins.rb', line 69

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



69
70
71
# File 'lib/vendor/puppet/util/plugins.rb', line 69

def path
  @path
end

Class Method Details

.knownObject

Return all the Puppet::Plugins we know about, searching any new paths



37
38
39
40
41
42
43
# File 'lib/vendor/puppet/util/plugins.rb', line 37

def self.known
  Paths[Loaded.length...Paths.length].each { |path|
    file = File.join(path,'plugin_init.rb')
    Loaded << (File.exist?(file) && new(file))
  }
  Loaded.compact
end

.look_in(*paths) ⇒ Object

Add more places to look for plugins without adding duplicates or changing the

order of ones we've already found.


48
49
50
# File 'lib/vendor/puppet/util/plugins.rb', line 48

def self.look_in(*paths)
  Paths.replace Paths | paths.flatten.collect { |path| File.expand_path(path) }
end

.method_missing(hook, *args, &block) ⇒ Object

Calling methods (hooks) on the class calls the method of the same name on

all plugins that use that hook, passing in the same arguments to each
and returning an array containing the results returned by each plugin as
an array of [plugin_name,result] pairs.


61
62
63
64
65
# File 'lib/vendor/puppet/util/plugins.rb', line 61

def self.method_missing(hook,*args,&block)
  known.
    select  { |p| p.respond_to? hook }.
    collect { |p| [p.name,p.send(hook,*args,&block)] }
end