Module: LazyController::Routable

Includes:
Studio54, Studio54::Config::Environment
Defined in:
lib/lazy_controller.rb

Overview

included in Dancefloor

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



48
49
50
51
# File 'lib/lazy_controller.rb', line 48

def self.included(base)
  base.__send__ :use, Rack::Flash
  base.__send__ :helpers, Sinatra::Partials
end

Instance Method Details

#controller(c_name, c_action, params = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/lazy_controller.rb', line 57

def controller(c_name, c_action, params={})
  require File.join(CONTROLLERSDIR, "#{c_name}_controller")
  require File.join(MODELSDIR, c_name[0...-1])
  begin
    controller = self.class.const_get("#{c_name.capitalize}Controller")
    controller_inst = controller.new
    result = if params.blank?
      controller_inst.__send__(c_action)
    else
      controller_inst.__send__(c_action, params)
    end
    controller_inst.instance_variables.each do |ivar|
      # establish non block-local scope
      ivar_value = nil
      controller_inst.instance_eval do
        ivar_value = instance_variable_get ivar
      end
      # self here is the instance of the application
      instance_variable_set ivar, ivar_value
    end
  ensure
    Db.conn.disconnect if Db.conn.kind_of? DBI::DatabaseHandle and
    Db.conn.connected?
  end
  result
end