As I said on the ticket, I don't think this is necessary - all we need to do is 
add the module lib dirs to Ruby's search path.

That way any library can be used, rather than having to specifically use any 
plugin system.

On Feb 20, 2011, at 2:58 AM, James Turnbull wrote:

> This is not a solution to the problem but just an idea
> and how I quickly solved it. I am sure there are more
> elegant ways of doing it.
> 
> Signed-off-by: James Turnbull <[email protected]>
> ---
> lib/puppet/util.rb              |    7 ++++---
> lib/puppet/util/plugins.rb      |    5 +++++
> lib/puppet/util/plugins/json.rb |   13 +++++++++++++
> 3 files changed, 22 insertions(+), 3 deletions(-)
> create mode 100644 lib/puppet/util/plugins.rb
> create mode 100644 lib/puppet/util/plugins/json.rb
> 
> diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
> index 850d147..cc0593d 100644
> --- a/lib/puppet/util.rb
> +++ b/lib/puppet/util.rb
> @@ -28,16 +28,16 @@ module Util
>     end
>   end
> 
> -  
> +
>   def self.synchronize_on(x,type)
>     sync_object,users = 0,1
>     begin
> -      @@sync_objects.synchronize { 
> +      @@sync_objects.synchronize {
>         (@@sync_objects[x] ||= [Sync.new,0])[users] += 1
>       }
>       @@sync_objects[x][sync_object].synchronize(type) { yield }
>     ensure
> -      @@sync_objects.synchronize { 
> +      @@sync_objects.synchronize {
>         @@sync_objects.delete(x) unless (@@sync_objects[x][users] -= 1) > 0
>       }
>     end
> @@ -462,3 +462,4 @@ require 'puppet/util/execution'
> require 'puppet/util/logging'
> require 'puppet/util/package'
> require 'puppet/util/warnings'
> +require 'puppet/util/plugins'
> diff --git a/lib/puppet/util/plugins.rb b/lib/puppet/util/plugins.rb
> new file mode 100644
> index 0000000..ace2662
> --- /dev/null
> +++ b/lib/puppet/util/plugins.rb
> @@ -0,0 +1,5 @@
> +require 'rubygems'
> +Gem.find_files('puppet/util/plugins/*.rb').each do |f|
> +  puts "#{f}"
> +  require f
> +end
> diff --git a/lib/puppet/util/plugins/json.rb b/lib/puppet/util/plugins/json.rb
> new file mode 100644
> index 0000000..18a99c2
> --- /dev/null
> +++ b/lib/puppet/util/plugins/json.rb
> @@ -0,0 +1,13 @@
> +# Adds json formatted ouput for Puppet applications.
> +# Usage: puppet agent --logdest json
> +# Currently there's no way to load this as a plugin, see #4248. Appending 
> this
> +# method to puppet/util/log/destinations.rb works. Meh.
> +# Would also be nice if Puppet::Util::Log had an #attributes method for 
> +# accessors instead of instance_variable hacks.
> +Puppet::Util::Log.newdesttype :json do
> +  def handle(msg)
> +    message = {}
> +    msg.instance_variables.each {|v| message[v.sub("@","")] = 
> msg.instance_variable_get(v) }
> +    puts message.to_pson
> +  end
> +end
> -- 
> 1.7.3.5
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
> 


-- 
Morgan's Second Law:
   To a first approximation all appointments are canceled.
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199




-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to