-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 4ce29dd
Showing
10 changed files
with
183 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL="redis://someremote-redis-saas:6379/15" |
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 @@ | ||
DATABASE_URL="redis://localhost:6379/1" |
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 @@ | ||
.rubocop-* |
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 @@ | ||
inherit_from: https://raw.githubusercontent.com/jodosha/dotfiles/master/rubocop.yml |
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "hanami-api", git: "https://github.com/hanami/api.git", branch: "feature/container" | ||
gem "dry-system", "~> 0.19" | ||
|
||
gem "puma" | ||
gem "redis" | ||
|
||
gem "byebug", require: false | ||
gem "rubocop" |
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,96 @@ | ||
GIT | ||
remote: https://github.com/hanami/api.git | ||
revision: 2c30a9ca301f2239b2e1d0150c31967dd2f6ca80 | ||
branch: feature/container | ||
specs: | ||
hanami-api (0.2.0) | ||
hanami-router (~> 2.0.alpha) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
ast (2.4.2) | ||
byebug (11.1.3) | ||
concurrent-ruby (1.1.8) | ||
dry-auto_inject (0.7.0) | ||
dry-container (>= 0.3.4) | ||
dry-configurable (0.12.1) | ||
concurrent-ruby (~> 1.0) | ||
dry-core (~> 0.5, >= 0.5.0) | ||
dry-container (0.7.2) | ||
concurrent-ruby (~> 1.0) | ||
dry-configurable (~> 0.1, >= 0.1.3) | ||
dry-core (0.5.0) | ||
concurrent-ruby (~> 1.0) | ||
dry-inflector (0.2.0) | ||
dry-logic (1.2.0) | ||
concurrent-ruby (~> 1.0) | ||
dry-core (~> 0.5, >= 0.5) | ||
dry-struct (1.4.0) | ||
dry-core (~> 0.5, >= 0.5) | ||
dry-types (~> 1.5) | ||
ice_nine (~> 0.11) | ||
dry-system (0.19.0) | ||
concurrent-ruby (~> 1.0) | ||
dry-auto_inject (>= 0.4.0) | ||
dry-configurable (~> 0.12, >= 0.12.1) | ||
dry-container (~> 0.7, >= 0.7.2) | ||
dry-core (~> 0.5, >= 0.5) | ||
dry-inflector (~> 0.1, >= 0.1.2) | ||
dry-struct (~> 1.0) | ||
dry-types (1.5.1) | ||
concurrent-ruby (~> 1.0) | ||
dry-container (~> 0.3) | ||
dry-core (~> 0.5, >= 0.5) | ||
dry-inflector (~> 0.1, >= 0.1.2) | ||
dry-logic (~> 1.0, >= 1.0.2) | ||
hanami-router (2.0.0.alpha5) | ||
mustermann (~> 1.0) | ||
mustermann-contrib (~> 1.0) | ||
rack (~> 2.0) | ||
hansi (0.2.0) | ||
ice_nine (0.11.2) | ||
mustermann (1.1.1) | ||
ruby2_keywords (~> 0.0.1) | ||
mustermann-contrib (1.1.1) | ||
hansi (~> 0.2.0) | ||
mustermann (= 1.1.1) | ||
nio4r (2.5.7) | ||
parallel (1.20.1) | ||
parser (3.0.1.1) | ||
ast (~> 2.4.1) | ||
puma (5.3.1) | ||
nio4r (~> 2.0) | ||
rack (2.2.3) | ||
rainbow (3.0.0) | ||
redis (4.2.5) | ||
regexp_parser (2.1.1) | ||
rexml (3.2.5) | ||
rubocop (1.14.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.0.0.0) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml | ||
rubocop-ast (>= 1.5.0, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 1.4.0, < 3.0) | ||
rubocop-ast (1.5.0) | ||
parser (>= 3.0.1.1) | ||
ruby-progressbar (1.11.0) | ||
ruby2_keywords (0.0.4) | ||
unicode-display_width (2.0.0) | ||
|
||
PLATFORMS | ||
x86_64-darwin-19 | ||
|
||
DEPENDENCIES | ||
byebug | ||
dry-system (~> 0.19) | ||
hanami-api! | ||
puma | ||
redis | ||
rubocop | ||
|
||
BUNDLED WITH | ||
2.2.16 |
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,15 @@ | ||
# MyApi | ||
|
||
Example `hanami-api` app with `dry-system` | ||
|
||
## Prerequisites | ||
|
||
* Ruby 3+ | ||
* Redis | ||
|
||
## How to run | ||
|
||
1. Clone this repository | ||
2. Run `bundle install` | ||
3. Start Redis | ||
4. Start the server via `bundle exec rackup` |
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "hanami/api" | ||
require "hanami/api/container" | ||
|
||
class Foo | ||
def call(arg) | ||
arg.to_s.upcase | ||
end | ||
end | ||
|
||
class MyApi < Hanami::API | ||
extend Hanami::API::Container | ||
|
||
configure do |config| | ||
config.root Pathname.new(Dir.pwd) | ||
end | ||
|
||
settings do | ||
key :database_url, Types::String.constrained(filled: true) | ||
end | ||
|
||
register "foo" do | ||
Foo.new | ||
end | ||
|
||
root do | ||
foo.call("hello") | ||
end | ||
|
||
get "/keys" do | ||
database.keys.join(", ") | ||
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "./app" | ||
|
||
run MyApi.new |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
MyApi.container.boot(:database) do |container| | ||
init do | ||
require "uri" | ||
require "redis" | ||
|
||
uri = URI.parse(container[:settings].database_url) | ||
redis = Redis.new(uri: uri.to_s) | ||
|
||
register(:database, redis) | ||
end | ||
|
||
stop do | ||
database.stop | ||
end | ||
end |