On Aug 24, 2008, at 5:56 AM, Brice Figureau wrote:

>
> Hi,

Sorry, probably should have replied to this one first.

>
> I'm unfortunately more a java/c/c++/perl guy than a ruby kind of
> programmer :-(

It's not too late. :)

>
> I started working on a service provider for daemontools, but I'm stuck
> with the following issue:
>
> Here is a snippet of my provider I produced using pattern matching  
> from
> other providers:
>
> Puppet::Type.type(:service).provide :daemontools, :parent => :base do
>    desc "Daemontools service management."
>
>    commands :svc  => "/usr/bin/svc"
>    commands :svstat => "/usr/bin/svstat"
>
>    class << self
>        attr_accessor :defpath
>        attr_accessor :srcpath
>    end
>
>    case Facter["operatingsystem"].value
>    when "Debian":
>        @defpath = "/etc/service"
>        @srcpath = "/var/lib/service"
>    else
>        @defpath = "/service"
>        @srcpath = "/var/lib/service"
>    end
>
> ...
>    def enabled?
>        appdir = File.join(self.defpath, @resource[:name])
>        FileTest.symlink?(appdir)
>    end
> ...

You've created a class accessor above -- that 'class << self...end'  
syntax is modifying the class, rather than instances, so you've made  
'defpath' and 'srcpath' class attributes.

However, your self.defpath call is using an instance attribute, since  
'enabled?' is an instance method.

Just change this to 'self.class.defpath'.  You wouldn't normally need  
the 'self', but you can't lead a statement with 'class' because it  
confuses Ruby's parser (since 'class' is a reserved word).
>
> What is the way to access properties of my provider in the provider  
> method
> (like status, start, stop...)

Provider, or resource?

You'd access resource attributes like: status = resource[:hasstatus].

Note that versions prior to, I think, 0.24.4 required you to use  
'resource.should(:property)' for properties. and 'resource[:param]'  
for parameters, for backward compatbility.  This has been fixed now,  
thankfully, and the [] syntax works everywhere.

-- 
Aizu's Second Law:
     What changes the world is communication, not information.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
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