Skip to content

Commit

Permalink
Use Zeitwerk for autoloading
Browse files Browse the repository at this point in the history
This commit introduces Zeitwerk [1] as the autoloader for WebPipe.

We eager-load in a test example to ensure the setup is correct.

[1] - https://github.com/fxn/zeitwerk
  • Loading branch information
waiting-for-dev committed Nov 14, 2023
1 parent 96dfe10 commit 8129f12
Show file tree
Hide file tree
Showing 59 changed files with 21 additions and 94 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ AllCops:
Metrics/BlockLength:
Exclude:
- spec/**/*
- web_pipe.gemspec

Naming/AccessorMethodName:
Enabled: false
Expand Down
1 change: 0 additions & 1 deletion docs/dsl_free_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ is exactly equivalent to:
```ruby
# config.ru
require 'web_pipe'
require 'web_pipe/pipe'

WebPipe.load_extensions(:params)

Expand Down
1 change: 0 additions & 1 deletion docs/extensions/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ are using the container configured in a connection instance.

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'
require 'my_container'

WebPipe.load_extensions(:container)
Expand Down
1 change: 0 additions & 1 deletion docs/extensions/dry_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ can be reused through composition by other applications.
require 'db'
require 'dry/schema'
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:dry_schema)

Expand Down
2 changes: 0 additions & 2 deletions docs/extensions/hanami_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ However, you can resolve a view from a container if you also use the
require 'hanami_view'
require 'my_container'
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:hanami_view, :container)

Expand Down Expand Up @@ -80,7 +79,6 @@ the view context class:

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:url)

Expand Down
1 change: 0 additions & 1 deletion docs/extensions/not_found.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ invocation. The `WebPipe::Conn#not_found` method will:

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:params, :not_found)

Expand Down
1 change: 0 additions & 1 deletion docs/extensions/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ key:

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:params)

Expand Down
2 changes: 0 additions & 2 deletions docs/extensions/rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class ApplicationController < ActionController::Base
end

# app/controllers/articles_index.rb
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:rails) # You can put it in an initializer

class ArticlesIndex
Expand Down
1 change: 0 additions & 1 deletion docs/extensions/router_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ transformation to the stack.

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'

WebPipe.load_extensions(:router_params)

Expand Down
1 change: 0 additions & 1 deletion docs/plugging_operations/inspecting_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ the `#operations` method:

```ruby
require 'web_pipe'
require 'web_pipe/conn_support/builder'

class MyApp
include WebPipe
Expand Down
1 change: 0 additions & 1 deletion docs/plugs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ attribute) to an instance of `WebPipe::Conn`.

```ruby
require 'web_pipe'
require 'web_pipe/plugs/config'

class MyApp
include WebPipe
Expand Down
1 change: 0 additions & 1 deletion docs/plugs/content_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Example:

```ruby
require 'web_pipe'
require 'web_pipe/plugs/content_type'

class MyApp
include WebPipe
Expand Down
13 changes: 12 additions & 1 deletion lib/web_pipe.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "dry/core/extensions"
require "web_pipe/dsl/builder"
require "zeitwerk"

# Entry-point for the DSL layer.
#
Expand Down Expand Up @@ -53,6 +53,17 @@
# }
# )
module WebPipe
def self.loader
Zeitwerk::Loader.for_gem.tap do |loader|
loader.ignore(
"#{__dir__}/web_pipe/conn_support/errors.rb",
"#{__dir__}/web_pipe/extensions"
)
loader.inflector.inflect("dsl" => "DSL")
end
end
loader.setup

extend Dry::Core::Extensions

# Called via {Module#include}, makes available web_pipe's DSL.
Expand Down
4 changes: 1 addition & 3 deletions lib/web_pipe/app.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "web_pipe/conn"
require "web_pipe/conn_support/builder"
require "web_pipe/conn_support/composition"
require "dry/monads"

module WebPipe
# Rack app built from a chain of functions that take and return a
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/conn.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

require "dry/struct"
require "web_pipe/conn_support/types"
require "web_pipe/conn_support/errors"
require "web_pipe/conn_support/headers"

module WebPipe
# Struct and methods about web request and response data.
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/conn_support/builder.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "rack"
require "web_pipe/conn"
require "web_pipe/conn_support/headers"

module WebPipe
module ConnSupport
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/conn_support/composition.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "dry/monads"
require "web_pipe/conn"

module WebPipe
module ConnSupport
Expand Down
4 changes: 0 additions & 4 deletions lib/web_pipe/dsl/builder.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

require "web_pipe/dsl/class_context"
require "web_pipe/dsl/instance_context"
require "web_pipe/pipe"

module WebPipe
module DSL
# @api private
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/dsl/instance_context.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe/pipe"

module WebPipe
module DSL
# @api private
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/extensions/container/container.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe"

# :nodoc:
module WebPipe
# See the docs for the extension linked from the README.
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/extensions/cookies/cookies.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe"
require "rack/utils"

# :nodoc:
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/extensions/dry_schema/dry_schema.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe"

WebPipe.load_extensions(:params)

# :nodoc:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/types"
require "web_pipe/extensions/dry_schema/dry_schema"

module WebPipe
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/extensions/flash/flash.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/conn"
require "web_pipe/conn_support/errors"

# :nodoc:
Expand Down
3 changes: 0 additions & 3 deletions lib/web_pipe/extensions/hanami_view/hanami_view.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require "web_pipe/types"
require "web_pipe/conn"
require "web_pipe"
require "web_pipe/extensions/hanami_view/hanami_view/context"
require "hanami/view"

Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/extensions/params/params.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/types"
require "web_pipe/extensions/params/params/transf"

# :nodoc:
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/extensions/rails/rails.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe/conn"

# :nodoc:
module WebPipe
# See the docs for the extension linked from the README.
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/extensions/redirect/redirect.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe/types"

# :nodoc:
module WebPipe
# See the docs for the extension linked from the README.
Expand Down
3 changes: 0 additions & 3 deletions lib/web_pipe/extensions/router_params/router_params.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require "web_pipe"
require "web_pipe/types"

WebPipe.load_extensions(:params)

module WebPipe
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/extensions/session/session.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "web_pipe/conn"
require "web_pipe/types"
require "rack"

# :nodoc:
Expand Down
9 changes: 0 additions & 9 deletions lib/web_pipe/pipe.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# frozen_string_literal: true

require "web_pipe/conn_support/composition"
require "web_pipe/app"
require "web_pipe/plug"
require "web_pipe/rack_support/middleware_specification"
require "web_pipe/rack_support/app_with_middlewares"
require "web_pipe/types"

module WebPipe
# Composable rack application builder.
#
Expand All @@ -28,8 +21,6 @@ module WebPipe
#
# @example
# # config.ru
# require 'web_pipe/pipe'
#
# app = WebPipe::Pipe.new
# .use(:runtime, Rack::Runtime)
# .plug(:content_type) do |conn|
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/plug.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "dry/struct"
require "web_pipe/types"
require "web_pipe/conn_support/composition"

module WebPipe
# @api private
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/rack_support/app_with_middlewares.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/rack_support/middleware"
require "rack"

module WebPipe
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/rack_support/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/types"
require "dry/struct"

module WebPipe
Expand Down
2 changes: 0 additions & 2 deletions lib/web_pipe/rack_support/middleware_specification.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "dry/struct"
require "web_pipe/rack_support/middleware"
require "web_pipe/types"

module WebPipe
module RackSupport
Expand Down
1 change: 0 additions & 1 deletion lib/web_pipe/test_support.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "web_pipe/conn_support/builder"
require "rack/mock"

module WebPipe
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/dry_schema/dry_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "spec_helper"
require "support/conn"
require "web_pipe"

RSpec.describe WebPipe::Conn do
before { WebPipe.load_extensions(:dry_schema) }
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/flash/flash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "spec_helper"
require "support/conn"
require "web_pipe/conn"
require "web_pipe/conn_support/errors"
require "rack-flash"

Expand Down
1 change: 0 additions & 1 deletion spec/extensions/flash/integration/flash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "spec_helper"
require "support/conn"
require "web_pipe"
require "rack/session/cookie"
require "rack-flash"

Expand Down
1 change: 0 additions & 1 deletion spec/extensions/hanami_view/hanami_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "support/conn"
require "hanami/view"
require "hanami/view/context"
require "web_pipe/conn"

RSpec.describe WebPipe::Conn do
before do
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/not_found/not_found_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require "web_pipe"
require "support/conn"

RSpec.describe WebPipe::Conn do
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/params/params_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require "web_pipe"
require "support/conn"

RSpec.describe WebPipe::Conn do
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/rails/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "spec_helper"
require "support/conn"
require "web_pipe/conn"

RSpec.describe WebPipe::Conn do
before do
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/session/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "spec_helper"
require "support/conn"
require "web_pipe"

RSpec.describe WebPipe::Conn do
before { WebPipe.load_extensions(:session) }
Expand Down
Loading

0 comments on commit 8129f12

Please sign in to comment.