Sha256: 9efd696d96d69d732b73692e1b941e70c68efd1d2e9df3b6bd9ab5fa90cf53a6

Contents?: true

Size: 1.35 KB

Versions: 18

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(raw: 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

18 entries across 18 versions & 1 rubygems

Version Path
jets-1.0.18 lib/jets/controller/base.rb
jets-1.0.17 lib/jets/controller/base.rb
jets-1.0.16 lib/jets/controller/base.rb
jets-1.0.15 lib/jets/controller/base.rb
jets-1.0.13 lib/jets/controller/base.rb
jets-1.0.12 lib/jets/controller/base.rb
jets-1.0.11 lib/jets/controller/base.rb
jets-1.0.10 lib/jets/controller/base.rb
jets-1.0.9 lib/jets/controller/base.rb
jets-1.0.8 lib/jets/controller/base.rb
jets-1.0.7 lib/jets/controller/base.rb
jets-1.0.6 lib/jets/controller/base.rb
jets-1.0.5 lib/jets/controller/base.rb
jets-1.0.4 lib/jets/controller/base.rb
jets-1.0.3 lib/jets/controller/base.rb
jets-1.0.2 lib/jets/controller/base.rb
jets-1.0.1 lib/jets/controller/base.rb
jets-1.0.0 lib/jets/controller/base.rb