Class: Rango::ControllerStrategy

to(“Post#show”, “blog/views”)

> Post.new(request).show(*args)

Constructor Summary

This class inherits a constructor from Rango::RouterStrategy.

Public Visibility

Public Class Methods Inherited from Rango::RouterStrategy

register

Public Instance Method Summary

#match?
#run

Public Instance Method Details

match?

public match?

Meta Tags

Parameters:

Since:

0.0.1

[View source]


36
37
38
39
40
# File 'lib/rango/router/strategies.rb', line 36

def match?
  self.args.length >= 2 &&
  self.args[0..1].all? { |arg| arg.is_a?(String) } &&
  ! block_given?
end

run

public run

Meta Tags

Parameters:

Version:

0.0.2

Since:

0.0.1

[View source]


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rango/router/strategies.rb', line 44

def run
  Rango.import("mvc/controller")
  file = self.args[0]
  callable = self.args[1]
  options  = self.args[2] || Hash.new
  Project.import(file) if file.is_a?(String)
  klass_name, method = callable.split("#")
  klass = Object.full_const_get(klass_name)
  raise "Controller expected, but #{klass} seems not to be controller" unless klass.controller?
  # match(%r[^/$]).to("eshop/views.rb", "Static#show", template: "index")
  # params. vs options: params are /post/:slug, options template: "index"
  klass.run(self.request, options.merge(params), method) # should returns [status, headers, body] (See Rack::Response#finish)
end