dry-web 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.rspec +3 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +16 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +21 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/lib/dry-web.rb +8 -0
- data/lib/dry/web/application.rb +34 -0
- data/lib/dry/web/cli.rb +17 -0
- data/lib/dry/web/container.rb +9 -0
- data/lib/dry/web/transaction.rb +19 -0
- data/lib/dry/web/version.rb +5 -0
- data/lib/roda/plugins/flow.rb +71 -0
- data/rodakase.gemspec +34 -0
- data/skeletons/simple/.ruby-version +1 -0
- data/skeletons/simple/Gemfile +11 -0
- data/skeletons/simple/README.md +21 -0
- data/skeletons/simple/Rakefile +4 -0
- data/skeletons/simple/bin/console +6 -0
- data/skeletons/simple/config.ru +3 -0
- data/skeletons/simple/config/application.yml +4 -0
- data/skeletons/simple/core/boot.rb +12 -0
- data/skeletons/simple/core/simple/application.rb +16 -0
- data/skeletons/simple/core/simple/container.rb +11 -0
- data/skeletons/simple/core/simple/import.rb +9 -0
- data/skeletons/simple/lib/entities/user.rb +3 -0
- data/skeletons/simple/log/.gitkeep +0 -0
- data/skeletons/simple/spec/routes/heartbeat_spec.rb +9 -0
- data/skeletons/simple/spec/spec_helper.rb +12 -0
- data/skeletons/simple/spec/unit/user_spec.rb +17 -0
- data/skeletons/simple/spec/web_helper.rb +20 -0
- data/skeletons/simple/web/routes/root.rb +3 -0
- data/spec/dummy/apps/main/core/boot.rb +15 -0
- data/spec/dummy/apps/main/core/main/application.rb +17 -0
- data/spec/dummy/apps/main/core/main/container.rb +16 -0
- data/spec/dummy/apps/main/core/main/import.rb +9 -0
- data/spec/dummy/apps/main/core/main/requests.rb +21 -0
- data/spec/dummy/apps/main/core/main/view.rb +21 -0
- data/spec/dummy/apps/main/lib/main/entities/user.rb +5 -0
- data/spec/dummy/apps/main/lib/main/persistence/repositories/users.rb +16 -0
- data/spec/dummy/apps/main/lib/main/transactions/register_user.rb +19 -0
- data/spec/dummy/apps/main/lib/main/views/users/index.rb +17 -0
- data/spec/dummy/apps/main/log/.gitkeep +0 -0
- data/spec/dummy/apps/main/requests/users.rb +5 -0
- data/spec/dummy/apps/main/web/routes/users.rb +19 -0
- data/spec/dummy/apps/main/web/templates/layouts/app.html.slim +6 -0
- data/spec/dummy/apps/main/web/templates/users/index.html.slim +3 -0
- data/spec/dummy/apps/main/web/templates/users/index/_list.html.slim +3 -0
- data/spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim +1 -0
- data/spec/dummy/bin/console +6 -0
- data/spec/dummy/config.ru +3 -0
- data/spec/dummy/config/application.yml +4 -0
- data/spec/dummy/core/boot.rb +8 -0
- data/spec/dummy/core/dummy/application.rb +7 -0
- data/spec/dummy/core/dummy/container.rb +14 -0
- data/spec/dummy/core/dummy/import.rb +9 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/shared/persistence.rb +12 -0
- data/spec/dummy/shared/persistence/db.rb +9 -0
- data/spec/fixtures/test/core/boot/bar.rb +11 -0
- data/spec/fixtures/test/lib/test/dep.rb +4 -0
- data/spec/fixtures/test/lib/test/foo.rb +5 -0
- data/spec/fixtures/test/lib/test/models.rb +4 -0
- data/spec/fixtures/test/lib/test/models/book.rb +6 -0
- data/spec/fixtures/test/lib/test/models/user.rb +6 -0
- data/spec/integration/application_spec.rb +21 -0
- data/spec/request/users_spec.rb +35 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/helpers.rb +15 -0
- metadata +322 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.3.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Simple Skeleton App
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
rackup
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Development
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ bundle exec rspec
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Run specs on file changes:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ ls **/*.rb | entr -c bundle exec rspec
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires [entr](http://entrproject.org/) to be installed.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative 'simple/container'
|
|
2
|
+
|
|
3
|
+
Simple::Container.finalize! do |container|
|
|
4
|
+
# Register your additional dependencies used by the web app
|
|
5
|
+
#
|
|
6
|
+
# In example a logger:
|
|
7
|
+
#
|
|
8
|
+
# require 'logger'
|
|
9
|
+
# container.register(:logger, Logger.new(container.root.join("log/#{container.config.env}.log")))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'simple/application'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'dry/web/application'
|
|
2
|
+
|
|
3
|
+
module Simple
|
|
4
|
+
class Application < Dry::Web::Application
|
|
5
|
+
configure do |config|
|
|
6
|
+
config.routes = 'web/routes'.freeze
|
|
7
|
+
config.container = Container
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
route do |r|
|
|
11
|
+
r.multi_route
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
load_routes!
|
|
15
|
+
end
|
|
16
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# set the env here since the app config loaded by container uses this name by
|
|
2
|
+
# default
|
|
3
|
+
ENV['RACK_ENV'] = 'test'
|
|
4
|
+
|
|
5
|
+
# Only load the container, if a test needs the whole web stack it should require
|
|
6
|
+
# web_helper instead
|
|
7
|
+
require_relative '../core/simple/container'
|
|
8
|
+
|
|
9
|
+
RSpec.configure do |config|
|
|
10
|
+
# Obviously
|
|
11
|
+
config.disable_monkey_patching!
|
|
12
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'entities/user'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Entities::User do
|
|
4
|
+
subject(:user) { Entities::User.new(1, 'Jane') }
|
|
5
|
+
|
|
6
|
+
describe '#id' do
|
|
7
|
+
it 'works' do
|
|
8
|
+
expect(user.id).to be(1)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#name' do
|
|
13
|
+
it 'works too' do
|
|
14
|
+
expect(user.name).to eql('Jane')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'rack/test'
|
|
4
|
+
|
|
5
|
+
require_relative '../core/boot'
|
|
6
|
+
|
|
7
|
+
module AppHelper
|
|
8
|
+
def app
|
|
9
|
+
Simple::Application.app
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.before(:suite) do
|
|
15
|
+
Simple::Application.freeze
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
config.include Rack::Test::Methods, type: :request
|
|
19
|
+
config.include AppHelper, type: :request
|
|
20
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require_relative 'main/container'
|
|
2
|
+
|
|
3
|
+
Main::Container.finalize! do |container|
|
|
4
|
+
require 'logger'
|
|
5
|
+
container.register(:logger, Logger.new(container.root.join('log/app.log')))
|
|
6
|
+
|
|
7
|
+
require 'dry/web/transaction'
|
|
8
|
+
container.register(:transaction, Dry::Web::Transaction::Composer.new(container))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require 'main/application'
|
|
12
|
+
require 'main/view'
|
|
13
|
+
require 'main/requests'
|
|
14
|
+
|
|
15
|
+
Main::Container.require('requests/**/*.rb')
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'dry/web/application'
|
|
2
|
+
require_relative 'container'
|
|
3
|
+
|
|
4
|
+
module Main
|
|
5
|
+
class Application < Dry::Web::Application
|
|
6
|
+
configure do |config|
|
|
7
|
+
config.routes = 'web/routes'.freeze
|
|
8
|
+
config.container = Main::Container
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
route do |r|
|
|
12
|
+
r.multi_route
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
load_routes!
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'dry/web/container'
|
|
2
|
+
|
|
3
|
+
module Main
|
|
4
|
+
class Container < Dry::Web::Container
|
|
5
|
+
configure do |config|
|
|
6
|
+
config.root = Pathname(__FILE__).join('../..').realpath.dirname.freeze
|
|
7
|
+
config.auto_register = 'lib'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require root.join('../../shared/persistence').to_s
|
|
11
|
+
|
|
12
|
+
import Persistence::Container
|
|
13
|
+
|
|
14
|
+
load_paths!('lib')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative 'container'
|
|
2
|
+
|
|
3
|
+
module Main
|
|
4
|
+
module Requests
|
|
5
|
+
class Registrar
|
|
6
|
+
attr_reader :container
|
|
7
|
+
|
|
8
|
+
def initialize(container)
|
|
9
|
+
@container = container
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def define(identifier, &block)
|
|
13
|
+
container.register(identifier, container[:transaction].define(&block))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.define(&block)
|
|
18
|
+
yield(Registrar.new(Container))
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'slim'
|
|
2
|
+
require 'dry-view'
|
|
3
|
+
|
|
4
|
+
require_relative 'container'
|
|
5
|
+
|
|
6
|
+
module Main
|
|
7
|
+
class Page
|
|
8
|
+
def title
|
|
9
|
+
'Woohaa'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Main
|
|
15
|
+
class View < Dry::View::Layout
|
|
16
|
+
setting :root, Container.root.join('web/templates')
|
|
17
|
+
setting :scope, Page.new
|
|
18
|
+
setting :formats, {html: :slim}
|
|
19
|
+
setting :name, 'app'.freeze
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'main/import'
|
|
2
|
+
require 'main/entities/user'
|
|
3
|
+
require 'kleisli'
|
|
4
|
+
|
|
5
|
+
module Main
|
|
6
|
+
module Transactions
|
|
7
|
+
class RegisterUser
|
|
8
|
+
include Main::Import('persistence.db')
|
|
9
|
+
|
|
10
|
+
def call(params)
|
|
11
|
+
if params['name']
|
|
12
|
+
Right(db[:users] << Main::Entities::User.new(*params.values_at('id', 'name')))
|
|
13
|
+
else
|
|
14
|
+
Left(validation: 'name is missing')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'main/view'
|
|
2
|
+
|
|
3
|
+
module Main
|
|
4
|
+
module Views
|
|
5
|
+
module Users
|
|
6
|
+
class Index < Main::View
|
|
7
|
+
configure do |config|
|
|
8
|
+
config.template = 'users/index'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def locals(options)
|
|
12
|
+
{ users: [{ name: 'Jane' }, { name: 'Joe' }] }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Main::Application < Dry::Web::Application
|
|
2
|
+
route('users') do |r|
|
|
3
|
+
r.get(to: 'main.views.users.index')
|
|
4
|
+
|
|
5
|
+
r.resolve('main.requests.users.create') do |t|
|
|
6
|
+
r.post do
|
|
7
|
+
t.(r[:user]) do |m|
|
|
8
|
+
m.success do
|
|
9
|
+
response.status = 201
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
m.failure do |err|
|
|
13
|
+
r.redirect '/users'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
li == user[:name]
|