Sha256: 4b55d6eefb975125c9ba9c4fe28ebfc58d80f5ce5c484c65a0e9dddcfcfb6132

Contents?: true

Size: 1.35 KB

Versions: 12

Compression:

Stored size: 1.35 KB

Contents

require "active_support/core_ext/hash"
require "active_support/core_ext/object"
require "json"
require "rack/utils" # Rack::Utils.parse_nested_query

# Controller public methods get turned into Lambda functions.
class Jets::Controller
  class Base < Jets::Lambda::Functions
    include Layout
    include Callbacks
    include Rendering
    include Params

    def self.process(event, context={}, meth)
      t1 = Time.now
      Jets.logger.info "Processing by #{self}##{meth}"

      controller = new(event, context, meth)

      Jets.logger.info "  Event: #{event.inspect}"
      Jets.logger.info "  Parameters: #{controller.params(true).to_h.inspect}"

      controller.run_before_actions
      controller.send(meth)
      resp = controller.ensure_render
      controller.run_after_actions

      took = Time.now - t1
      Jets.logger.info "Completed Status Code #{resp["statusCode"]} in #{took}s"

      resp
    end

    delegate :headers, to: :request
    delegate :set_header, to: :response
    attr_reader :request, :response
    def initialize(event, context={}, meth)
      super
      @request = Request.new(event)
      @response = Response.new(event)
    end

    class_attribute :internal_controller
    def self.internal(value=nil)
      if !value.nil?
        self.internal_controller = value
      else
        self.internal_controller
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jets-0.10.4 lib/jets/controller/base.rb
jets-0.10.3 lib/jets/controller/base.rb
jets-0.10.2 lib/jets/controller/base.rb
jets-0.10.1 lib/jets/controller/base.rb
jets-0.10.0 lib/jets/controller/base.rb
jets-0.9.2 lib/jets/controller/base.rb
jets-0.9.1 lib/jets/controller/base.rb
jets-0.9.0 lib/jets/controller/base.rb
jets-0.8.18 lib/jets/controller/base.rb
jets-0.8.17 lib/jets/controller/base.rb
jets-0.8.15 lib/jets/controller/base.rb
jets-0.8.14 lib/jets/controller/base.rb