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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +30 -0
  5. data/CHANGELOG.md +16 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +21 -0
  8. data/LICENSE +22 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +46 -0
  11. data/Rakefile +6 -0
  12. data/lib/dry-web.rb +8 -0
  13. data/lib/dry/web/application.rb +34 -0
  14. data/lib/dry/web/cli.rb +17 -0
  15. data/lib/dry/web/container.rb +9 -0
  16. data/lib/dry/web/transaction.rb +19 -0
  17. data/lib/dry/web/version.rb +5 -0
  18. data/lib/roda/plugins/flow.rb +71 -0
  19. data/rodakase.gemspec +34 -0
  20. data/skeletons/simple/.ruby-version +1 -0
  21. data/skeletons/simple/Gemfile +11 -0
  22. data/skeletons/simple/README.md +21 -0
  23. data/skeletons/simple/Rakefile +4 -0
  24. data/skeletons/simple/bin/console +6 -0
  25. data/skeletons/simple/config.ru +3 -0
  26. data/skeletons/simple/config/application.yml +4 -0
  27. data/skeletons/simple/core/boot.rb +12 -0
  28. data/skeletons/simple/core/simple/application.rb +16 -0
  29. data/skeletons/simple/core/simple/container.rb +11 -0
  30. data/skeletons/simple/core/simple/import.rb +9 -0
  31. data/skeletons/simple/lib/entities/user.rb +3 -0
  32. data/skeletons/simple/log/.gitkeep +0 -0
  33. data/skeletons/simple/spec/routes/heartbeat_spec.rb +9 -0
  34. data/skeletons/simple/spec/spec_helper.rb +12 -0
  35. data/skeletons/simple/spec/unit/user_spec.rb +17 -0
  36. data/skeletons/simple/spec/web_helper.rb +20 -0
  37. data/skeletons/simple/web/routes/root.rb +3 -0
  38. data/spec/dummy/apps/main/core/boot.rb +15 -0
  39. data/spec/dummy/apps/main/core/main/application.rb +17 -0
  40. data/spec/dummy/apps/main/core/main/container.rb +16 -0
  41. data/spec/dummy/apps/main/core/main/import.rb +9 -0
  42. data/spec/dummy/apps/main/core/main/requests.rb +21 -0
  43. data/spec/dummy/apps/main/core/main/view.rb +21 -0
  44. data/spec/dummy/apps/main/lib/main/entities/user.rb +5 -0
  45. data/spec/dummy/apps/main/lib/main/persistence/repositories/users.rb +16 -0
  46. data/spec/dummy/apps/main/lib/main/transactions/register_user.rb +19 -0
  47. data/spec/dummy/apps/main/lib/main/views/users/index.rb +17 -0
  48. data/spec/dummy/apps/main/log/.gitkeep +0 -0
  49. data/spec/dummy/apps/main/requests/users.rb +5 -0
  50. data/spec/dummy/apps/main/web/routes/users.rb +19 -0
  51. data/spec/dummy/apps/main/web/templates/layouts/app.html.slim +6 -0
  52. data/spec/dummy/apps/main/web/templates/users/index.html.slim +3 -0
  53. data/spec/dummy/apps/main/web/templates/users/index/_list.html.slim +3 -0
  54. data/spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim +1 -0
  55. data/spec/dummy/bin/console +6 -0
  56. data/spec/dummy/config.ru +3 -0
  57. data/spec/dummy/config/application.yml +4 -0
  58. data/spec/dummy/core/boot.rb +8 -0
  59. data/spec/dummy/core/dummy/application.rb +7 -0
  60. data/spec/dummy/core/dummy/container.rb +14 -0
  61. data/spec/dummy/core/dummy/import.rb +9 -0
  62. data/spec/dummy/log/.gitkeep +0 -0
  63. data/spec/dummy/shared/persistence.rb +12 -0
  64. data/spec/dummy/shared/persistence/db.rb +9 -0
  65. data/spec/fixtures/test/core/boot/bar.rb +11 -0
  66. data/spec/fixtures/test/lib/test/dep.rb +4 -0
  67. data/spec/fixtures/test/lib/test/foo.rb +5 -0
  68. data/spec/fixtures/test/lib/test/models.rb +4 -0
  69. data/spec/fixtures/test/lib/test/models/book.rb +6 -0
  70. data/spec/fixtures/test/lib/test/models/user.rb +6 -0
  71. data/spec/integration/application_spec.rb +21 -0
  72. data/spec/request/users_spec.rb +35 -0
  73. data/spec/spec_helper.rb +44 -0
  74. data/spec/support/helpers.rb +15 -0
  75. metadata +322 -0
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'dry-web', github: 'dry-rb/dry-web'
4
+ gem 'pry'
5
+ gem 'pry-byebug', platform: 'mri'
6
+ gem 'rake'
7
+
8
+ group :test do
9
+ gem 'rack-test'
10
+ gem 'rspec'
11
+ end
@@ -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,4 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: [:spec]
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rodakase/cli'
4
+ require_relative '../core/boot'
5
+
6
+ Rodakase::Cli.start
@@ -0,0 +1,3 @@
1
+ require_relative 'core/boot'
2
+
3
+ run Simple::Application.freeze.app
@@ -0,0 +1,4 @@
1
+ development:
2
+ SOMETHING: 'goes-here'
3
+ test:
4
+ SOMETHING: 'goes-here'
@@ -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
@@ -0,0 +1,11 @@
1
+ require 'dry/web/container'
2
+
3
+ module Simple
4
+ class Container < Dry::Web::Container
5
+ setting :auto_register, 'lib'
6
+
7
+ configure do
8
+ load_paths!('lib')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'container'
2
+
3
+ module Simple
4
+ Import = Container.import_module
5
+
6
+ def self.Import(*args)
7
+ Import[*args]
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Entities
2
+ User = Struct.new(:id, :name)
3
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ require 'web_helper'
2
+
3
+ RSpec.describe '/hearbeat', type: :request do
4
+ it 'works' do
5
+ get '/heartbeat'
6
+
7
+ expect(last_response).to be_ok
8
+ end
9
+ end
@@ -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,3 @@
1
+ class Simple::Application < Dry::Web::Application
2
+ plugin :heartbeat
3
+ 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,9 @@
1
+ require_relative 'container'
2
+
3
+ module Main
4
+ Import = Main::Container.import_module
5
+
6
+ def self.Import(*args)
7
+ Import[*args]
8
+ end
9
+ 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,5 @@
1
+ module Main
2
+ module Entities
3
+ User = Struct.new(:id, :name)
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'main/import'
2
+ require 'main/entities/user'
3
+
4
+ module Main
5
+ module Persistence
6
+ module Repositories
7
+ class Users
8
+ include Main::Import('persistence.db')
9
+
10
+ def all
11
+ db[:users]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ 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,5 @@
1
+ Main::Requests.define do |r|
2
+ r.define('main.requests.users.create') do
3
+ step 'main.transactions.register_user'
4
+ end
5
+ end
@@ -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,6 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title == page.title
5
+ body
6
+ == yield
@@ -0,0 +1,3 @@
1
+ h1 Users
2
+
3
+ .users == users.list
@@ -0,0 +1,3 @@
1
+ ul
2
+ - users.each do |user|
3
+ == user.list_item
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dry/web/cli'
4
+ # require_relative '../core/boot'
5
+
6
+ Dry::Web::Cli.start
@@ -0,0 +1,3 @@
1
+ require_relative 'core/boot'
2
+
3
+ run Dummy::Application.freeze.app