Parent

Files

Class/Module Index [+]

Quicksearch

Rufus::TreeChecker::RuleSet

Public Class Methods

new() click to toggle source
# File lib/rufus/treechecker.rb, line 216
def initialize

  @excluded_symbols = {} # symbol => exclusion_message
  @accepted_patterns = {} # 1st elt of pattern => pattern
  @excluded_patterns = {} # 1st elt of pattern => pattern, excl_message
end

Public Instance Methods

accept_pattern(pat) click to toggle source
# File lib/rufus/treechecker.rb, line 236
def accept_pattern (pat)

  (@accepted_patterns[pat.first] ||= []) << pat
end
check(sexp) click to toggle source
# File lib/rufus/treechecker.rb, line 247
def check (sexp)

  if sexp.is_a?(Symbol)

    m = @excluded_symbols[sexp]
    raise SecurityError.new(m) if m

  elsif sexp.is_a?(Array)

    # accepted patterns are evaluated before excluded patterns
    # if one is found the excluded patterns are skipped

    pats = @accepted_patterns[sexp.first]
    pats.each { |pat| return if check_pattern(sexp, pat) } if pats

    pats = @excluded_patterns[sexp.first]
    return unless pats

    pats.each do |pat, msg|
      raise SecurityError.new(msg) if check_pattern(sexp, pat)
    end
  end
end
clone() click to toggle source
# File lib/rufus/treechecker.rb, line 223
def clone
  rs = RuleSet.new
  rs.instance_variable_set(:@excluded_symbols, @excluded_symbols.dup)
  rs.instance_variable_set(:@accepted_patterns, @accepted_patterns.dup)
  rs.instance_variable_set(:@excluded_patterns, @excluded_patterns.dup)
  rs
end
exclude_pattern(pat, message) click to toggle source
# File lib/rufus/treechecker.rb, line 241
def exclude_pattern (pat, message)

  (@excluded_patterns[pat.first] ||= []) << [
    pat, message || "#{pat.inspect} is excluded" ]
end
exclude_symbol(s, message) click to toggle source
# File lib/rufus/treechecker.rb, line 231
def exclude_symbol (s, message)

  @excluded_symbols[s] = (message || ":#{s} is excluded")
end
freeze() click to toggle source
# File lib/rufus/treechecker.rb, line 271
def freeze

  super

  @excluded_symbols.freeze
  @excluded_symbols.each { |k, v| k.freeze; v.freeze }
  @accepted_patterns.freeze
  @accepted_patterns.each { |k, v| k.freeze; v.freeze }
  @excluded_patterns.freeze
  @excluded_patterns.each { |k, v| k.freeze; v.freeze }
end
to_s() click to toggle source
# File lib/rufus/treechecker.rb, line 283
def to_s

  s = "#{self.class} (#{self.object_id})\n"
  s << "  excluded symbols :\n"
  @excluded_symbols.each do |k, v|
    s << "    - #{k.inspect}, #{v}\n"
  end
  s << "  accepted patterns :\n"
  @accepted_patterns.each do |k, v|
    v.each do |p|
      s << "    - #{k.inspect}, #{p.inspect}\n"
    end
  end
  s << "  excluded patterns :\n"
  @excluded_patterns.each do |k, v|
    v.each do |p|
      s << "    - #{k.inspect}, #{p.inspect}\n"
    end
  end
  s
end

Protected Instance Methods

check_pattern(sexp, pat) click to toggle source
# File lib/rufus/treechecker.rb, line 307
def check_pattern (sexp, pat)

  return false if sexp.length < pat.length

  (1..pat.length-1).each do |i|
    return false if (pat[i] != :any and pat[i] != sexp[i])
  end

  return true # we have a match
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.