Methods
public class
public instance
protected instance
Public class methods
new
()
[show source]
# File lib/rufus/treechecker.rb, line 216 216: def initialize 217: 218: @excluded_symbols = {} # symbol => exclusion_message 219: @accepted_patterns = {} # 1st elt of pattern => pattern 220: @excluded_patterns = {} # 1st elt of pattern => pattern, excl_message 221: end
Public instance methods
accept_pattern
(pat)
[show source]
# File lib/rufus/treechecker.rb, line 236 236: def accept_pattern (pat) 237: 238: (@accepted_patterns[pat.first] ||= []) << pat 239: end
check
(sexp)
[show source]
# File lib/rufus/treechecker.rb, line 247 247: def check (sexp) 248: 249: if sexp.is_a?(Symbol) 250: 251: m = @excluded_symbols[sexp] 252: raise SecurityError.new(m) if m 253: 254: elsif sexp.is_a?(Array) 255: 256: # accepted patterns are evaluated before excluded patterns 257: # if one is found the excluded patterns are skipped 258: 259: pats = @accepted_patterns[sexp.first] 260: pats.each { |pat| return if check_pattern(sexp, pat) } if pats 261: 262: pats = @excluded_patterns[sexp.first] 263: return unless pats 264: 265: pats.each do |pat, msg| 266: raise SecurityError.new(msg) if check_pattern(sexp, pat) 267: end 268: end 269: end
clone
()
[show source]
# File lib/rufus/treechecker.rb, line 223 223: def clone 224: rs = RuleSet.new 225: rs.instance_variable_set(:@excluded_symbols, @excluded_symbols.dup) 226: rs.instance_variable_set(:@accepted_patterns, @accepted_patterns.dup) 227: rs.instance_variable_set(:@excluded_patterns, @excluded_patterns.dup) 228: rs 229: end
exclude_pattern
(pat, message)
[show source]
# File lib/rufus/treechecker.rb, line 241 241: def exclude_pattern (pat, message) 242: 243: (@excluded_patterns[pat.first] ||= []) << [ 244: pat, message || "#{pat.inspect} is excluded" ] 245: end
exclude_symbol
(s, message)
[show source]
# File lib/rufus/treechecker.rb, line 231 231: def exclude_symbol (s, message) 232: 233: @excluded_symbols[s] = (message || ":#{s} is excluded") 234: end
freeze
()
[show source]
# File lib/rufus/treechecker.rb, line 271 271: def freeze 272: 273: super 274: 275: @excluded_symbols.freeze 276: @excluded_symbols.each { |k, v| k.freeze; v.freeze } 277: @accepted_patterns.freeze 278: @accepted_patterns.each { |k, v| k.freeze; v.freeze } 279: @excluded_patterns.freeze 280: @excluded_patterns.each { |k, v| k.freeze; v.freeze } 281: end
to_s
()
[show source]
# File lib/rufus/treechecker.rb, line 283 283: def to_s 284: 285: s = "#{self.class} (#{self.object_id})\n" 286: s << " excluded symbols :\n" 287: @excluded_symbols.each do |k, v| 288: s << " - #{k.inspect}, #{v}\n" 289: end 290: s << " accepted patterns :\n" 291: @accepted_patterns.each do |k, v| 292: v.each do |p| 293: s << " - #{k.inspect}, #{p.inspect}\n" 294: end 295: end 296: s << " excluded patterns :\n" 297: @excluded_patterns.each do |k, v| 298: v.each do |p| 299: s << " - #{k.inspect}, #{p.inspect}\n" 300: end 301: end 302: s 303: end
Protected instance methods
check_pattern
(sexp, pat)
[show source]
# File lib/rufus/treechecker.rb, line 307 307: def check_pattern (sexp, pat) 308: 309: return false if sexp.length < pat.length 310: 311: (1..pat.length-1).each do |i| 312: return false if (pat[i] != :any and pat[i] != sexp[i]) 313: end 314: 315: return true # we have a match 316: end