Method: Bj::ClassMethods#chroot

Defined in:
lib/bj/bj.rb

#chroot(options = {}, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bj/bj.rb', line 45

def chroot options = {}, &block
  if defined? @chrooted and @chrooted
    return(block ? block.call(@chrooted) : @chrooted)
  end
  if block
    begin
      chrooted = @chrooted
      Dir.chdir(@chrooted = rails_root) do
        raise RailsRoot, "<#{ Dir.pwd }> is not a rails root" unless Util.valid_rails_root?(Dir.pwd)
        block.call(@chrooted)
      end
    ensure
      @chrooted = chrooted 
    end
  else
    Dir.chdir(@chrooted = rails_root)
    raise RailsRoot, "<#{ Dir.pwd }> is not a rails root" unless Util.valid_rails_root?(Dir.pwd)
    @chrooted
  end
end