~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/parser/ast/leaf.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
            return @value
11
11
        end
12
12
 
 
13
        # evaluate ourselves, and match
 
14
        def evaluate_match(value, scope, options = {})
 
15
            obj = self.safeevaluate(scope)
 
16
            if ! options[:sensitive] && obj.respond_to?(:downcase)
 
17
                obj = obj.downcase
 
18
            end
 
19
            obj == value
 
20
        end
 
21
 
 
22
        def match(value)
 
23
            @value == value
 
24
        end
 
25
 
13
26
        def to_s
14
 
            return @value
 
27
            return @value.to_s unless @value.nil?
15
28
        end
16
29
    end
17
30
 
29
42
            end
30
43
            @value
31
44
        end
 
45
 
 
46
        def to_s
 
47
            @value ? "true" : "false"
 
48
        end
32
49
    end
33
50
 
34
51
    # The base string class.
38
55
        def evaluate(scope)
39
56
            return scope.strinterp(@value, file, line)
40
57
        end
 
58
 
 
59
        def to_s
 
60
            "\"#{@value}\""
 
61
        end
41
62
    end
42
63
 
43
64
    # An uninterpreted string.
45
66
        def evaluate(scope)
46
67
            return @value
47
68
        end
 
69
 
 
70
        def to_s
 
71
            "\"#{@value}\""
 
72
        end
48
73
    end
49
74
 
50
75
    # The 'default' option on case statements and selectors.
64
89
    # undef values; equiv to nil
65
90
    class Undef < AST::Leaf; end
66
91
 
67
 
    # Host names, either fully qualified or just the short name
 
92
    # Host names, either fully qualified or just the short name, or even a regex
68
93
    class HostName < AST::Leaf
69
94
        def initialize(hash)
70
95
            super
71
96
 
72
 
            unless @value =~ %r{^[0-9a-zA-Z\-]+(\.[0-9a-zA-Z\-]+)*$}
 
97
            @value = @value.to_s.downcase unless @value.is_a?(Regex)
 
98
            if @value =~ /[^-\w.]/
73
99
                raise Puppet::DevError,
74
100
                    "'%s' is not a valid hostname" % @value
75
101
            end
76
102
        end
 
103
 
 
104
        def to_classname
 
105
            to_s.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'')
 
106
        end
 
107
 
 
108
        # implementing eql? and hash so that when an HostName is stored
 
109
        # in a hash it has the same hashing properties as the underlying value
 
110
        def eql?(value)
 
111
            value = value.value if value.is_a?(HostName)
 
112
            return @value.eql?(value)
 
113
        end
 
114
 
 
115
        def hash
 
116
            return @value.hash
 
117
        end
 
118
 
 
119
        def match(value)
 
120
            return @value.match(value) unless value.is_a?(HostName)
 
121
 
 
122
            if value.regex? and self.regex?
 
123
                # Wow this is some sweet design; maybe a touch of refactoring
 
124
                # in order here.
 
125
                return value.value.value == self.value.value
 
126
            elsif value.regex? # we know if the existing name is not a regex, it won't match a regex
 
127
                return false
 
128
            else
 
129
                # else, we could be either a regex or normal and it doesn't matter
 
130
                return @value.match(value.value)
 
131
            end
 
132
        end
 
133
 
 
134
        def regex?
 
135
            @value.is_a?(Regex)
 
136
        end
 
137
 
 
138
        def to_s
 
139
            @value.to_s
 
140
        end
77
141
    end
78
142
 
79
143
    # A simple variable.  This object is only used during interpolation;
87
151
            end
88
152
        end
89
153
    end
 
154
 
 
155
    class Regex < AST::Leaf
 
156
        def initialize(hash)
 
157
            super
 
158
            @value = Regexp.new(@value) unless @value.is_a?(Regexp)
 
159
        end
 
160
 
 
161
        # we're returning self here to wrap the regexp and to be used in places
 
162
        # where a string would have been used, without modifying any client code.
 
163
        # For instance, in many places we have the following code snippet:
 
164
        #  val = @val.safeevaluate(@scope)
 
165
        #  if val.match(otherval)
 
166
        #      ...
 
167
        #  end
 
168
        # this way, we don't have to modify this test specifically for handling
 
169
        # regexes.
 
170
        def evaluate(scope)
 
171
            return self
 
172
        end
 
173
 
 
174
        def evaluate_match(value, scope, options = {})
 
175
            value = value.is_a?(String) ? value : value.to_s
 
176
 
 
177
            if matched = @value.match(value)
 
178
                scope.ephemeral_from(matched, options[:file], options[:line])
 
179
            end
 
180
            matched
 
181
        end
 
182
 
 
183
        def match(value)
 
184
            @value.match(value)
 
185
        end
 
186
 
 
187
        def to_s
 
188
            return "/#{@value.source}/"
 
189
        end
 
190
    end
90
191
end