public
Description: A library for safe evaluation of Ruby code based on ParseTree/RubyParser and Ruby2Ruby. Provides Rails ActionView template handlers for ERB and Haml.
Homepage: http://www.artweb-design.de
Clone URL: git://github.com/svenfuchs/safemode.git
safemode / lib / safemode / exceptions.rb
100644 22 lines (19 sloc) 0.677 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Safemode
  class Error < RuntimeError; end
  
  class SecurityError < Error
    @@types = { :const => 'constant',
                :xstr => 'shell command',
                :fcall => 'method',
                :vcall => 'method',
                :gvar => 'global variable' }
               
    def initialize(type, value = nil)
      type = @@types[type] if @@types.include?(type)
      super "Safemode doesn't allow to access '#{type}'" + (value ? " on #{value}" : '')
    end
  end
  
  class NoMethodError < Error
    def initialize(method, jail, source = nil)
      super "undefined method '#{method}' for #{jail}" + (source ? " (#{source})" : '')
    end
  end
end