On Mon, Feb 9, 2009 at 3:16 PM, Luke Kanies <l...@madstop.com> wrote:
> Not a biggie, but you could do this short-circuit instead: > > launchctl(:list).split("\n").each do |j| > return :running if j.split(/\s/).last == resource[:name] > end > return :stopped ahah. That's how I do it... I couldn't quite work out the syntax. I've just realized though that I'm not coping with the command not returning anything but appearing to succeed which might lead to: $ ruby -e 'nil.split("\n")' -e:1: private method `split' called for nil:NilClass (NoMethodError) > > Or even: > > if launchctl(:list).split(/\n/).detect { |j| j.split(/\s/).last == > resource[:name] } > return :running > else > return :stopped > end > > Or (the intent is maybe cleaner, although ): > > if launchtl(:list).split(/\n/).collect { |j| j.split(/ > \s/).last }.detect { |n| n == resource[:name] } > ...same code as above... > > Probably the first is actually best, just because it splits out that > big one-liner, but they all reduce 10 lines of code quite a bit, and > get rid of the temporary variable. Note that 'detect' automatically > short-cuts, so that's helpful. definitely. That's a useful tip. > > Otherwise, looks good. > >> >> rescue Puppet::ExecutionFailure >> - return :stopped >> + raise Puppet::Error.new("Unable to determine status of >> #{resource[:name]}") >> end >> end >> >> -- >> 1.5.3.1 >> >> >> > > > > -- > I have an answering machine in my car. It says, "I'm home now. But > leave a message and I'll call when I'm out. -- Stephen Wright > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > > > -- Nigel Kersten Systems Administrator Tech Lead - MacOps --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---