Class: Usher::Util::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/util/rails.rb

Class Method Summary collapse

Class Method Details

.activateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/usher/util/rails.rb', line 5

def self.activate
  rails_version = "#{::Rails::VERSION::MAJOR}.#{::Rails::VERSION::MINOR}"

  case rails_version
  when '2.3'
    ActionController::Routing.module_eval "remove_const(:Routes); Routes = Usher::Interface.for(:rails23)"

  when '2.2'
    Usher::Interface::Rails22::Mapper.module_eval("include ActionController::Resources")
    ActionController::Routing.module_eval "remove_const(:Routes); Routes = Usher::Interface.for(:rails22)"

  when '2.0'
    Usher::Interface::Rails20::Mapper.module_eval("include ActionController::Resources")
    ActionController::Routing.module_eval <<-CODE
      remove_const(:Routes);
      interface = Usher::Interface.for(:rails20);
      interface.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
      Routes = interface;
    CODE
  when '3.0'
    ActionController::Routing.module_eval <<-CODE
      remove_const(:Routes);
      interface = Usher::Interface.for(:rails20);
      interface.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
      Routes = interface;
    CODE
  end
end