Module: Ripl::Rails

Defined in:
lib/ripl/rails.rb

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_rails_root!Object



7
8
9
10
11
12
# File 'lib/ripl/rails.rb', line 7

def self.find_rails_root!
  until Pathname.pwd.join('config', 'boot.rb').exist?
    abort "Not in a Rails environment" if Pathname.pwd.root?
    Dir.chdir '..'
  end
end

.load_railsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ripl/rails.rb', line 14

def self.load_rails
  ENV['RAILS_ENV'] = ARGV[0] if ARGV[0].to_s[/^[^-]/]

  require "#{Dir.pwd}/config/boot"
  if File.exists?("#{Dir.pwd}/config/application.rb")
    Object.const_set :APP_PATH, File.expand_path("#{Dir.pwd}/config/application")
    require APP_PATH

    require 'rails/console/app'
    require 'rails/console/helpers'
    if defined?(Rails::ConsoleMethods)
      Ripl::Commands.include Rails::ConsoleMethods
    end

    ::Rails.application.require_environment!
  else
    ["#{Dir.pwd}/config/environment", 'console_app', 'console_with_helpers'].each {|e| require e }
  end
  puts "Loading #{::Rails.env} environment (Rails #{::Rails.version})"
end

Instance Method Details

#before_loopObject



35
36
37
38
39
# File 'lib/ripl/rails.rb', line 35

def before_loop
  Ripl::Rails.find_rails_root!
  Ripl::Rails.load_rails
  super
end