Sha256: 85cd29127589ea3d62b6da2d8cec5e60edbb489b27562dac49c2c623e14255bb

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

class Usher
  module Interface
    class Rails3Interface
    
      @@instance = nil
    
      def initialize
        @usher = Usher.new
        @controller_paths = []
        @configurations_files = []
        
        @@instance = self
      end
      
      def self.instance
        @@instance
      end
      
      def draw(&blk)
        @usher.instance_eval(&blk)
      end
      
      attr_accessor :controller_paths
      
      def add_configuration_file(file)
        @configurations_files << file
      end
      
      def reload
        @usher.reset!
        @configurations_files.each do |c|
          Kernel.load(c)
        end
      end
      alias_method :reload!, :reload
      
      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

      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
      
      def load(app)
        @app = app
      end
      
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
joshbuddy-usher-0.5.6 lib/usher/interface/rails3_interface.rb
joshbuddy-usher-0.5.7 lib/usher/interface/rails3_interface.rb
usher-0.5.11 lib/usher/interface/rails3_interface.rb
usher-0.5.10 lib/usher/interface/rails3_interface.rb
usher-0.5.8 lib/usher/interface/rails3_interface.rb
usher-0.5.7 lib/usher/interface/rails3_interface.rb
usher-0.5.6 lib/usher/interface/rails3_interface.rb