Class: GoldenBrindle::RailsSupport

Inherits:
Object
  • Object
show all
Defined in:
lib/golden_brindle/rails_support.rb

Class Method Summary collapse

Class Method Details

.rails2?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/golden_brindle/rails_support.rb', line 9

def rails2?
  ::Rails::VERSION::MAJOR == 2
end

.rails3?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/golden_brindle/rails_support.rb', line 5

def rails3?
  ::Rails::VERSION::MAJOR == 3
end

.rails3_applicationObject



19
20
21
22
23
24
25
# File 'lib/golden_brindle/rails_support.rb', line 19

def rails3_application
  return unless rails3? || ::File.exist?('config/application.rb')
  return Object.const_get($1)::Application if \
     ::File.read('config/application.rb') =~ /^module\s+([\w:]+)\s*$/
rescue NameError
  nil
end

.rails_builder(daemonize) ⇒ Object



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/golden_brindle/rails_support.rb', line 35

def rails_builder(daemonize)
  # this lambda won't run until after forking if preload_app is false
  lambda do ||
    # Load Rails
    begin
      require ::File.expand_path('config/boot')
      require ::File.expand_path('config/environment')
    rescue LoadError => e
      abort "#{$0} must be run inside RAILS_ROOT: #{e.inspect}"
    end

    defined?(::Rails::VERSION::STRING) or
      abort "Rails::VERSION::STRING not defined by config/{boot,environment}"

    old_rails = !support_rack?

    ::Rack::Builder.new do
      map_path = ENV['RAILS_RELATIVE_URL_ROOT'] || '/'
      if old_rails
        if map_path != '/'
          warn "relative URL roots may not work for older Rails"
        end
        warn "LogTailer not available for Rails < 2.3" unless daemonize
        warn "Debugger not available" if $DEBUG
        require 'unicorn/app/old_rails'
        map(map_path) do
          use Unicorn::App::OldRails::Static
          run Unicorn::App::OldRails.new
        end
      else
        use Rails::Rack::LogTailer unless daemonize
        use Rails::Rack::Debugger if $DEBUG
        map(map_path) do
          unless defined?(ActionDispatch::Static)
            use Rails::Rack::Static
          end
          run ::GoldenBrindle::RailsSupport.rails_dispatcher
        end
      end
    end.to_app
  end
end

.rails_dispatcherObject



27
28
29
30
31
32
33
# File 'lib/golden_brindle/rails_support.rb', line 27

def rails_dispatcher
  result = rails3_application
  if result.nil? && defined?(ActionController::Dispatcher)
    result = ActionController::Dispatcher.new
  end
  result || abort("Unable to locate the application dispatcher class")
end

.support_rack?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/golden_brindle/rails_support.rb', line 13

def support_rack?
  return true if rails3?
  return true if rails2? && ::Rails::VERSION::MINOR >= 3
  false
end