dry-web 0.1.0 → 0.2.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +1 -10
  4. data/README.md +0 -3
  5. data/{rodakase.gemspec → dry-web.gemspec} +3 -10
  6. data/lib/dry-web.rb +0 -4
  7. data/lib/dry/web/version.rb +1 -1
  8. data/spec/spec_helper.rb +7 -16
  9. data/spec/unit/container_spec.rb +52 -0
  10. metadata +11 -200
  11. data/lib/dry/web/application.rb +0 -34
  12. data/lib/dry/web/transaction.rb +0 -19
  13. data/lib/roda/plugins/flow.rb +0 -71
  14. data/skeletons/simple/.ruby-version +0 -1
  15. data/skeletons/simple/Gemfile +0 -11
  16. data/skeletons/simple/README.md +0 -21
  17. data/skeletons/simple/Rakefile +0 -4
  18. data/skeletons/simple/bin/console +0 -6
  19. data/skeletons/simple/config.ru +0 -3
  20. data/skeletons/simple/config/application.yml +0 -4
  21. data/skeletons/simple/core/boot.rb +0 -12
  22. data/skeletons/simple/core/simple/application.rb +0 -16
  23. data/skeletons/simple/core/simple/container.rb +0 -11
  24. data/skeletons/simple/core/simple/import.rb +0 -9
  25. data/skeletons/simple/lib/entities/user.rb +0 -3
  26. data/skeletons/simple/log/.gitkeep +0 -0
  27. data/skeletons/simple/spec/routes/heartbeat_spec.rb +0 -9
  28. data/skeletons/simple/spec/spec_helper.rb +0 -12
  29. data/skeletons/simple/spec/unit/user_spec.rb +0 -17
  30. data/skeletons/simple/spec/web_helper.rb +0 -20
  31. data/skeletons/simple/web/routes/root.rb +0 -3
  32. data/spec/dummy/apps/main/core/boot.rb +0 -15
  33. data/spec/dummy/apps/main/core/main/application.rb +0 -17
  34. data/spec/dummy/apps/main/core/main/container.rb +0 -16
  35. data/spec/dummy/apps/main/core/main/import.rb +0 -9
  36. data/spec/dummy/apps/main/core/main/requests.rb +0 -21
  37. data/spec/dummy/apps/main/core/main/view.rb +0 -21
  38. data/spec/dummy/apps/main/lib/main/entities/user.rb +0 -5
  39. data/spec/dummy/apps/main/lib/main/persistence/repositories/users.rb +0 -16
  40. data/spec/dummy/apps/main/lib/main/transactions/register_user.rb +0 -19
  41. data/spec/dummy/apps/main/lib/main/views/users/index.rb +0 -17
  42. data/spec/dummy/apps/main/log/.gitkeep +0 -0
  43. data/spec/dummy/apps/main/requests/users.rb +0 -5
  44. data/spec/dummy/apps/main/web/routes/users.rb +0 -19
  45. data/spec/dummy/apps/main/web/templates/layouts/app.html.slim +0 -6
  46. data/spec/dummy/apps/main/web/templates/users/index.html.slim +0 -3
  47. data/spec/dummy/apps/main/web/templates/users/index/_list.html.slim +0 -3
  48. data/spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim +0 -1
  49. data/spec/dummy/bin/console +0 -6
  50. data/spec/dummy/config.ru +0 -3
  51. data/spec/dummy/config/application.yml +0 -4
  52. data/spec/dummy/core/boot.rb +0 -8
  53. data/spec/dummy/core/dummy/application.rb +0 -7
  54. data/spec/dummy/core/dummy/container.rb +0 -14
  55. data/spec/dummy/core/dummy/import.rb +0 -9
  56. data/spec/dummy/log/.gitkeep +0 -0
  57. data/spec/dummy/shared/persistence.rb +0 -12
  58. data/spec/dummy/shared/persistence/db.rb +0 -9
  59. data/spec/fixtures/test/core/boot/bar.rb +0 -11
  60. data/spec/fixtures/test/lib/test/dep.rb +0 -4
  61. data/spec/fixtures/test/lib/test/foo.rb +0 -5
  62. data/spec/fixtures/test/lib/test/models.rb +0 -4
  63. data/spec/fixtures/test/lib/test/models/book.rb +0 -6
  64. data/spec/fixtures/test/lib/test/models/user.rb +0 -6
  65. data/spec/integration/application_spec.rb +0 -21
  66. data/spec/request/users_spec.rb +0 -35
  67. data/spec/support/helpers.rb +0 -15
@@ -1,34 +0,0 @@
1
- require 'roda'
2
- require 'dry-configurable'
3
-
4
- module Dry
5
- module Web
6
- class Application < Roda
7
- extend Dry::Configurable
8
-
9
- setting :container
10
- setting :routes
11
-
12
- plugin :multi_route
13
- plugin :all_verbs
14
-
15
- plugin :flow
16
-
17
- def self.resolve(name)
18
- config.container[name]
19
- end
20
-
21
- def self.[](name)
22
- resolve(name)
23
- end
24
-
25
- def self.load_routes!
26
- Dir[root.join("#{config.routes}/**/*.rb")].each { |f| require f }
27
- end
28
-
29
- def self.root
30
- config.container.config.root
31
- end
32
- end
33
- end
34
- end
@@ -1,19 +0,0 @@
1
- require 'dry-transaction'
2
-
3
- module Dry
4
- module Web
5
- module Transaction
6
- class Composer
7
- attr_reader :container
8
-
9
- def initialize(container)
10
- @container = container
11
- end
12
-
13
- def define(&block)
14
- Dry.Transaction(container: container, &block)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,71 +0,0 @@
1
- # this is taken from roda-flow plugin but it drops dependency on roda-container
2
- class Roda
3
- module RodaPlugins
4
- module Flow
5
- module RequestMethods
6
- def resolve(*args, &block)
7
- on(resolve: args, &block)
8
- end
9
-
10
- private
11
-
12
- def match_resolve(resolve)
13
- Array(resolve).flatten.each do |key|
14
- @captures << roda_class.resolve(key)
15
- end
16
- end
17
-
18
- def match_to(to)
19
- container_key, @block_method = to.to_s.split('#')
20
- @block_arg = roda_class.resolve(container_key)
21
- end
22
-
23
- def match_inject(inject)
24
- @block_arg = @block_arg.call(*inject) if @block_arg
25
- end
26
-
27
- def match_call_with(call_with)
28
- @captures.concat(call_with)
29
- end
30
-
31
- def if_match(*args, &block)
32
- path = @remaining_path
33
- # For every block, we make sure to reset captures so that
34
- # nesting matchers won't mess with each other's captures.
35
- @captures.clear
36
-
37
- return unless match_all(args)
38
- block_result(get_block(&block).call(*captures))
39
- throw :halt, response.finish
40
- ensure
41
- @remaining_path = path
42
- end
43
-
44
- def always(&block)
45
- super(&get_block(&block))
46
- end
47
-
48
- def get_block(&block)
49
- if block_given?
50
- block
51
- elsif @block_arg
52
- if @block_method
53
- block_arg = @block_arg.method(@block_method)
54
- else
55
- block_arg = @block_arg
56
- end
57
- clear_block_args
58
- block_arg
59
- end
60
- end
61
-
62
- def clear_block_args
63
- @block_arg = nil
64
- @block_method = nil
65
- end
66
- end
67
- end
68
-
69
- register_plugin(:flow, Flow)
70
- end
71
- end
@@ -1 +0,0 @@
1
- 2.3.0
@@ -1,11 +0,0 @@
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
@@ -1,21 +0,0 @@
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.
@@ -1,4 +0,0 @@
1
- require "rspec/core/rake_task"
2
-
3
- RSpec::Core::RakeTask.new(:spec)
4
- task default: [:spec]
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rodakase/cli'
4
- require_relative '../core/boot'
5
-
6
- Rodakase::Cli.start
@@ -1,3 +0,0 @@
1
- require_relative 'core/boot'
2
-
3
- run Simple::Application.freeze.app
@@ -1,4 +0,0 @@
1
- development:
2
- SOMETHING: 'goes-here'
3
- test:
4
- SOMETHING: 'goes-here'
@@ -1,12 +0,0 @@
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'
@@ -1,16 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- module Entities
2
- User = Struct.new(:id, :name)
3
- end
File without changes
@@ -1,9 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,17 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- class Simple::Application < Dry::Web::Application
2
- plugin :heartbeat
3
- end
@@ -1,15 +0,0 @@
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')
@@ -1,17 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- module Main
2
- module Entities
3
- User = Struct.new(:id, :name)
4
- end
5
- end