On Apr 16, 2010, at 10:43 AM, Maxim Ianoglo wrote:

Hello,

Trying to make a custom type

Type:
module Puppet
   newtype(:simple_line) do

       ensurable

       newparam(:name) do
           isnamevar
       end

       newproperty(:target) do
           defaultto {
               if
                   @resource.class.defaultprovider.ancestors.include?
Puppet::Provider::ParsedFile
                   @resource.class.defaultprovider.default_target
               else
                   nil
               end
           }
       end

       newproperty(:pcre_pattern) do
           validate do |value|
               if value.class != String
                   raise ArgumentError, "Shoult be string"
               else
                   super
               end
           end
       end

       newproperty(:line) do
           validate do |value|
               if value.is_a? String
                   raise ArgumentError, "Shoult be string"
               else
                   super
               end
           end
       end
   end
end

Provider:
require 'puppet/provider/parsedfile'

target = "/tmp/simple_line_dummy_file"

Puppet::Type.type(:simple_line).provide(
   :parsed,
   :parent => Puppet::Provider::ParsedFile,
   :default_target => target,
   :filetype => :flat
) do

   text_line :comment,
             :match => @resource.value(:pcre_pattern)

Here's your problem - @resource is being evaluated in the provider class, where it resolves to nil.

There isn't really any good way to have ParsedFile dynamically split files based on a value passed into a resource - the regex in that case is resource-specific, but the file covers many resources.

What are you trying to accomplish that led you down this path?

   text_line :blank,
             :match => /^\s*$/

   record_line :parsed,
               :fields => %w{line}
end

But I keep getting this error: NoMethodError: undefined method `value'
for nil:NilClass

How can i fix this ?


--
Getting caught is the mother of invention. --Robert Byrne
---------------------------------------------------------------------
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