Parent

Class Index [+]

Quicksearch

Rufus::TreeChecker::RuleSet

Public Class Methods

new() click to toggle source
     # File lib/rufus/treechecker.rb, line 206
206:       def initialize
207: 
208:         @excluded_symbols = {} # symbol => exclusion_message
209:         @accepted_patterns = {} # 1st elt of pattern => pattern
210:         @excluded_patterns = {} # 1st elt of pattern => pattern, excl_message
211:       end

Public Instance Methods

accept_pattern(pat) click to toggle source
     # File lib/rufus/treechecker.rb, line 226
226:       def accept_pattern(pat)
227: 
228:         (@accepted_patterns[pat.first] ||= []) << pat
229:       end
check(sexp) click to toggle source
     # File lib/rufus/treechecker.rb, line 237
237:       def check(sexp)
238: 
239:         if sexp.is_a?(Symbol)
240: 
241:           m = @excluded_symbols[sexp]
242:           raise SecurityError.new(m) if m
243: 
244:         elsif sexp.is_a?(Array)
245: 
246:           # accepted patterns are evaluated before excluded patterns
247:           # if one is found the excluded patterns are skipped
248: 
249:           pats = @accepted_patterns[sexp.first]
250:           pats.each { |pat| return if check_pattern(sexp, pat) } if pats
251: 
252:           pats = @excluded_patterns[sexp.first]
253:           return unless pats
254: 
255:           pats.each do |pat, msg|
256:             raise SecurityError.new(msg) if check_pattern(sexp, pat)
257:           end
258:         end
259:       end
clone() click to toggle source
     # File lib/rufus/treechecker.rb, line 213
213:       def clone
214:         rs = RuleSet.new
215:         rs.instance_variable_set(:@excluded_symbols, @excluded_symbols.dup)
216:         rs.instance_variable_set(:@accepted_patterns, @accepted_patterns.dup)
217:         rs.instance_variable_set(:@excluded_patterns, @excluded_patterns.dup)
218:         rs
219:       end
exclude_pattern(pat, message) click to toggle source
     # File lib/rufus/treechecker.rb, line 231
231:       def exclude_pattern(pat, message)
232: 
233:         (@excluded_patterns[pat.first] ||= []) << [
234:           pat, message || "#{pat.inspect} is excluded" ]
235:       end
exclude_symbol(s, message) click to toggle source
     # File lib/rufus/treechecker.rb, line 221
221:       def exclude_symbol(s, message)
222: 
223:         @excluded_symbols[s] = (message || ":#{s} is excluded")
224:       end
freeze() click to toggle source
     # File lib/rufus/treechecker.rb, line 261
261:       def freeze
262: 
263:         super
264: 
265:         @excluded_symbols.freeze
266:         @excluded_symbols.each { |k, v| k.freeze; v.freeze }
267:         @accepted_patterns.freeze
268:         @accepted_patterns.each { |k, v| k.freeze; v.freeze }
269:         @excluded_patterns.freeze
270:         @excluded_patterns.each { |k, v| k.freeze; v.freeze }
271:       end
to_s() click to toggle source
     # File lib/rufus/treechecker.rb, line 273
273:       def to_s
274: 
275:         s = "#{self.class} (#{self.object_id})\n"
276:         s << "  excluded symbols :\n"
277:         @excluded_symbols.each do |k, v|
278:           s << "    - #{k.inspect}, #{v}\n"
279:         end
280:         s << "  accepted patterns :\n"
281:         @accepted_patterns.each do |k, v|
282:           v.each do |p|
283:             s << "    - #{k.inspect}, #{p.inspect}\n"
284:           end
285:         end
286:         s << "  excluded patterns :\n"
287:         @excluded_patterns.each do |k, v|
288:           v.each do |p|
289:             s << "    - #{k.inspect}, #{p.inspect}\n"
290:           end
291:         end
292:         s
293:       end

Protected Instance Methods

check_pattern(sexp, pat) click to toggle source
     # File lib/rufus/treechecker.rb, line 297
297:       def check_pattern(sexp, pat)
298: 
299:         return false if sexp.length < pat.length
300: 
301:         (1..pat.length-1).each do |i|
302:           return false if (pat[i] != :any and pat[i] != sexp[i])
303:         end
304: 
305:         return true # we have a match
306:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.