Class: Usher::Interface::Rails3

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/interface/rails3.rb

Constant Summary collapse

@@instance =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRails3

Returns a new instance of Rails3.



7
8
9
10
11
12
13
# File 'lib/usher/interface/rails3.rb', line 7

def initialize
  @usher = Usher.new
  @controller_paths = []
  @configurations_files = []
  
  @@instance = self
end

Instance Attribute Details

#controller_pathsObject

Returns the value of attribute controller_paths.



23
24
25
# File 'lib/usher/interface/rails3.rb', line 23

def controller_paths
  @controller_paths
end

Class Method Details

.instanceObject



15
16
17
# File 'lib/usher/interface/rails3.rb', line 15

def self.instance
  @@instance
end

Instance Method Details

#add_configuration_file(file) ⇒ Object



25
26
27
# File 'lib/usher/interface/rails3.rb', line 25

def add_configuration_file(file)
  @configurations_files << file
end

#call(env) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/usher/interface/rails3.rb', line 37

def call(env)
  request = ActionDispatch::Request.new(env)
  response = @usher.recognize(request, request.path_info)
  request.parameters.merge!(response.path.route.default_values) if response.path.route.default_values
  response.params.each{ |hk| request.parameters[hk.first] = hk.last}
  controller = "#{request.parameters[:controller].to_s.camelize}Controller".constantize
  controller.action(request.parameters[:action] || 'index').call(env)
end

#draw(&blk) ⇒ Object



19
20
21
# File 'lib/usher/interface/rails3.rb', line 19

def draw(&blk)
  @usher.instance_eval(&blk)
end

#load(app) ⇒ Object



52
53
54
# File 'lib/usher/interface/rails3.rb', line 52

def load(app)
  @app = app
end

#recognize(request) ⇒ Object



46
47
48
49
50
# File 'lib/usher/interface/rails3.rb', line 46

def recognize(request)
  params = recognize_path(request.path, extract_request_environment(request))
  request.path_parameters = params.with_indifferent_access
  "#{params[:controller].to_s.camelize}Controller".constantize
end

#reloadObject Also known as: reload!



29
30
31
32
33
34
# File 'lib/usher/interface/rails3.rb', line 29

def reload
  @usher.reset!
  @configurations_files.each do |c|
    Kernel.load(c)
  end
end