Class: Convict::Jail
- Inherits:
-
Object
- Object
- Convict::Jail
- Defined in:
- lib/convict/jail.rb
Instance Attribute Summary collapse
-
#guard ⇒ Object
readonly
Returns the value of attribute guard.
Instance Method Summary collapse
- #debug(str) ⇒ Object
-
#initialize(_path) ⇒ Jail
constructor
A new instance of Jail.
- #run ⇒ Object
Constructor Details
#initialize(_path) ⇒ Jail
Returns a new instance of Jail.
4 5 6 7 |
# File 'lib/convict/jail.rb', line 4 def initialize(_path) @guard = false @path = _path end |
Instance Attribute Details
#guard ⇒ Object (readonly)
Returns the value of attribute guard.
2 3 4 |
# File 'lib/convict/jail.rb', line 2 def guard @guard end |
Instance Method Details
#debug(str) ⇒ Object
9 10 11 12 |
# File 'lib/convict/jail.rb', line 9 def debug(str) return unless ENV["CONVICT_DEBUG"] puts str end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/convict/jail.rb', line 14 def run tp = TracePoint.new do |tp| debug " #{@guard} - #{tp.self} - #{tp.defined_class} - #{tp.callee_id} - #{tp.event} - #{tp.method_id}" if @guard case tp.event when :c_call case tp.method_id when :method_missing when :set_encoding raise "not IO" unless tp.defined_class == IO when :require, :load raise "not Kernel" unless tp.defined_class == Kernel when :new when :initialize when :inherited when :method_added when :singleton_method_added when :puts debug ">> GUARD OFF" @guard = false else if tp.self.is_a? Exception raise tp.self else raise Convict::Violation, "#{tp.defined_class}.#{tp.method_id}" end end end else case tp.event when :c_call case tp.method_id when :instance_eval debug " >> CELL LOCKED" @guard = true end when :c_return if tp.method_id == :puts debug " >> GUARD ON" @guard = true end end end end contents = File.read @path begin Convict::Cell.new contents, @path, tp rescue Convict::Violation => ex puts "" puts "VIOLATION: #{ex}" exit 1 rescue => ex puts "" puts "EXCEPTION:" puts ex..split("for #<Convict")[0] puts "in #{ex.backtrace_locations[1].to_s.split(":in `block").first}" else #puts "cell value: #{$value}" end end |