Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/adblockplus/lib/puppet/parser/functions/ensure_state.rb

Issue 29370632: NoIssue - Refactor ensure_*state functions (Closed)
Patch Set: Created Jan. 3, 2017, 2:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # coding: utf-8
2 # vi: set fenc=utf-8 ft=ruby ts=8 sw=2 sts=2 et:
3 module Puppet::Parser::Functions
4
5 newfunction(:ensure_state, :type => :rvalue, :doc => <<-'begin') do |args|
6 Returns true if the given parameter does not match any keyword commonly
7 associated with absence, false otherwise.
8 begin
9
10 usage = 'Usage: ensure_state($resource_or_string)'
11 raise Puppet::ParseError, usage unless args.size == 1
12
13 if args[0].nil?
14 result = false
15 else
16
17 if args[0].is_a? String
18 value = args[0]
19 elsif resource = findresource(args[0].to_s)
20 value = resource['ensure'].to_s
21 else
22 raise Puppet::ParseError, usage
23 end
24
25 if value.match(/^(absent|false|purged|stopped)$/)
26 result = false
27 else
28 result = true
29 end
30
31 end
32
33 return result
34
35 end
36
37 end
OLDNEW

Powered by Google App Engine
This is Rietveld