-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
name: Ruby | ||
name: CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- '.github/workflows/ci.yml' | ||
- 'lib/**' | ||
- '*.gemspec' | ||
- 'spec/**' | ||
- 'Rakefile' | ||
- 'Gemfile' | ||
- '.rubocop.yml' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
pull_request: | ||
schedule: | ||
- cron: '30 4 * * *' | ||
create: | ||
|
||
jobs: | ||
build: | ||
rubocop: | ||
runs-on: ubuntu-latest | ||
name: Rubocop | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.2' | ||
bundler-cache: true | ||
- name: Run linter | ||
run: bundle exec rake rubocop | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
name: Ruby ${{ matrix.ruby }} | ||
strategy: | ||
matrix: | ||
ruby: | ||
- '3.3.0' | ||
|
||
- '3.2' | ||
- '3.1' | ||
- '3.0' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler-cache: true | ||
- name: Run the default task | ||
- name: Run all tests | ||
run: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hanami | ||
module Lambda | ||
# The application to configure for AWS Lambda. | ||
# | ||
# @since 0.1.0 | ||
class Application | ||
# @api private | ||
def self.inherited(subclass) | ||
super | ||
|
||
Hanami::Lambda.app = subclass | ||
subclass.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
# Dispatch event to the handler | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
def call(event:, context:) | ||
handler = lookup(event: event, context: context) | ||
handler.call | ||
end | ||
|
||
# Lookup the handler for the given event | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
def lookup(event:, context:) | ||
Rack.new(Hanami.app, event: event, context: context) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hanami | ||
module Lambda | ||
# Rack interface for AWS Lambda. | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
class Rack | ||
attr_reader :app, :event, :context | ||
|
||
# @api private | ||
def initialize(app, event:, context:) | ||
@app = app | ||
@event = event | ||
@context = context | ||
end | ||
|
||
# Handle the request | ||
# | ||
# @return [Hash] the response | ||
# | ||
# @since 0.1.0 | ||
def call | ||
status_code, headers, body = app.call(env) | ||
|
||
{ | ||
statusCode: status_code, | ||
headers: headers, | ||
body: body.join | ||
} | ||
end | ||
|
||
# Build the Rack environment | ||
# | ||
# @return [Hash] the Rack environment | ||
# | ||
# @since 0.1.0 | ||
def env | ||
{ | ||
::Rack::REQUEST_METHOD => event["httpMethod"], | ||
::Rack::PATH_INFO => event["path"] || "", | ||
::Rack::VERSION => ::Rack::VERSION, | ||
::Rack::RACK_INPUT => StringIO.new(event["body"] || "") | ||
} | ||
end | ||
end | ||
end | ||
end |