Sha256: 818978973f0001b18fa3baab5c278d91f064c253ec84009577fb3a74b5252487
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
require 'happy/controller/routing' require 'happy/controller/actions' require 'happy/controller/rackable' module Happy class Controller include Routing include Actions include Rackable attr_reader :options, :env, :root_path delegate :request, :response, :params, :session, :previous_path, :remaining_path, :render, :url_for, :to => :context def initialize(env = {}, options = {}, &blk) @env = env @options = options # Save a copy of the current path as this controller's root path. @root_path = context.previous_path.dup # Execute block against this instance, allowing the controller to # provide a DSL for configuration. instance_exec(&blk) if blk end def perform context.with_controller(self) do route end end protected def url(extras = nil) url_for(previous_path, extras) end def root_url(extras = nil) url_for(root_path, extras) end private def context @env['happy.context'] ||= self.class.context_class.from_env(@env) end def route instance_exec(&self.class.route_blk) if self.class.route_blk end class << self attr_reader :route_blk def route(&blk) @route_blk = blk end def context(&blk) context_class.class_exec(&blk) end def context_class Happy::Context end def build(&blk) Class.new(self).tap do |klass| klass.instance_eval(&blk) if blk end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
happy-0.1.0.pre11 | lib/happy/controller.rb |
happy-0.1.0.pre10 | lib/happy/controller.rb |