- From: Andrea Campi <
>
- To: "
" <
>
- Cc: "
" <
>
- Subject: [chef] Re: where is the better place for this code?
- Date: Wed, 16 Nov 2011 09:19:49 +0100
There are a few examples of this pattern in some providers in the base Chef.
The service provider for FreeBSD should be an example.
This should probably be factored out into a common class or mixin for easier
reuse in custom cookbooks.
On Nov 16, 2011, at 12:41 AM, Juan Jesús Ojeda Croissier
<
>
wrote:
>
Hi :-)
>
>
I'm quite new here, but I really love the project and the community.
>
You all are great :-)
>
>
Well, I was writting a couple of new cookbooks for a project[1] where
>
I'm working on and I found that I need very often to check if some
>
string is in a file and replace just one string keepking the rest of
>
the file as it was.
>
>
For example a file that a user (or app) can write and usually does.
>
Maybe we like to be sure that specific value for a key is always the
>
right one, but not to change the part of the file where the user (or
>
app) has already changed.
>
>
I wrote some code for this (which is currently working), but I don't
>
know if I did in the right place and in the right way. I love to have
>
it at Chef, but I guess it need to be proven useful and the community
>
agree. By now I put it in my cookbooks at:
>
cookbooks/the_cookbook/libraries/file.rb
>
>
Here is the actual code and example or recipe using it:
>
https://gist.github.com/1368640
>
>
But I'll write down here a simplier version:
>
>
def include?(str)
>
file_content = ::File.open(@path).read
>
return true if file_content =~ /#{str}/
>
return false
>
end
>
>
def replace(str, str2)
>
old_content = ::File.open(@path).read
>
content old_content.gsub(str, str2)
>
end
>
>
These methods are Chef::Resource::File's methods. I wrote like that
>
because was the only way I got them working, but it seems to me that
>
it should be a Providers' instead... I don't know...
Looking only at your gist it's a wash, but in general yes, I would use an
LWRP. Keep the library, but put the "file" resource in an LWRP.
>
>
I hope you guy could give me some light about it. And also tell me if
>
you find this interesting enough to have it at Chef itself. I'm pretty
>
sure that I gonna use them a lot for my recipes...
>
>
Thanks a lot for your time.
>
Cheers
>
>
>
[1] http://www.guadalinex.org
>
http://goo.gl/WSoU2 (google treanslated version of the actual project)
>
--
>
Juanje
- [chef] where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/15/2011
- [chef] Re: where is the better place for this code?, hani elabed, 11/15/2011
- [chef] Re: where is the better place for this code?, Andrea Campi, 11/16/2011
- [chef] Re: Re: where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/16/2011
- [chef] Re: Re: Re: where is the better place for this code?, Andrea Campi, 11/16/2011
- [chef] Re: Re: Re: Re: where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/16/2011
- [chef] Re: Re: Re: Re: Re: where is the better place for this code?, Andrea Campi, 11/16/2011
- [chef] Re: Re: Re: Re: Re: Re: where is the better place for this code?, Daniel DeLeo, 11/17/2011
- [chef] Re: Re: Re: Re: Re: Re: Re: where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/17/2011
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: where is the better place for this code?, John E. Vincent (lusis), 11/17/2011
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/17/2011
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: where is the better place for this code?, Matthew Moretti, 11/17/2011
- [chef] Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: where is the better place for this code?, Juan Jesús Ojeda Croissier, 11/17/2011
Archive powered by MHonArc 2.6.16.