Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ jobs:
- "3.0"
- "2.7"
- "2.6"
dummy:
- "with-engine"
- "without-engine"
include:
- ruby: "3.0"
coverage: "true"
env:
COVERAGE: ${{matrix.coverage}}
COVERAGE_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
TEST_DUMMY: ${{matrix.dummy}}
steps:
- name: Checkout
uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
steps:
- name: Checkout ${{github.repository}}
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Checkout devtools
uses: actions/checkout@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ Style/CombinableLoops:
Style/EmptyElse:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/MultilineBlockChain:
Enabled: false

Lint/UnusedBlockArgument:
Exclude:
- "spec/**/*.rb"
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->

## unreleased
## 0.4.0 2021-12-23

This is a big update - please also read dry-system [CHANGELOG](https://github.com/dry-rb/dry-system/blob/master/CHANGELOG.md) versions 0.20 and 0.21.

### Added

Expand All @@ -11,8 +12,11 @@

- `config.auto_inject_constant` is now cleared during code reloading (see #40 for more info) (@diegotoral)

### Changed

- Updated to work with dry-system 0.21 (via #48 and #50) (@zlw + @solnic)

[Compare v0.3.0...master](https://github.com/dry-rb/dry-rails/compare/v0.3.0...master)
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-rails/compare/v0.3.0...v0.4.0)

## 0.3.0 2020-08-26

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end

group :test do
gem "rspec-rails"
gem "super_engine", path: "spec/dummies/with-engine/dummy/engines/super_engine", require: false
end

group :tools do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
This library officially supports the following Ruby versions:

* MRI `>= 2.6.0`
* ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
* jruby `>= 9.3`

## License

Expand Down
23 changes: 12 additions & 11 deletions changelog.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
---
- version: unreleased
summary:
date:
- version: 0.4.0
summary: "This is a big update - please also read dry-system [CHANGELOG](https://github.com/dry-rb/dry-system/blob/master/CHANGELOG.md) versions 0.20 and 0.21."
date: 2021-12-23
fixed:
- "`config.auto_inject_constant` is now cleared during code reloading (see #40 for
more info) (@diegotoral)"
added:
- 'It''s now possible to configure container constant name via `config.constainer_const_name`
(issue #21 closed via #41) (@diegotoral)'
changed:
changed:
- 'Updated to work with dry-system 0.21 (via #48 and #50) (@zlw + @solnic)'
- version: 0.3.0
summary:
summary:
date: 2020-08-26
fixed:
added:
fixed:
added:
changed:
- 'Use dry-system 0.18.0 and configure new `bootable_dirs` setting appropriately
(@timriley in #38)'
- version: 0.2.1
summary:
summary:
date: 2020-08-26
fixed:
- Fix dry-system dependency to 0.17.0, to avoid incompatibilities with 0.18.0 (@timriley)
added:
- 'Controller features now support `ActionControll::API` too (issue #35 closed via
#36) (@rinaldifonseca)'
changed:
changed:
- version: 0.2.0
summary:
summary:
date: 2020-07-21
fixed:
- 'Resolving `Container` constant looks it up only within the application namespace
Expand All @@ -52,4 +53,4 @@
and exposes `safe_params` controller helper (@solnic)"
- "`:controller_helpers` feature which adds `ApplicationController#{resolve,container}`
shortcuts (@solnic)"
changed:
changed:
2 changes: 1 addition & 1 deletion docsite/source/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Currently, the railtie **does not make any assumptions about your directory/file
Dry::Rails.container do
config.component_dirs.add "app/operations"
config.component_dirs.add "lib" do |dir|
dir.default_namespace = "my_super_cool_app"
dir.namespaces.add "my_super_cool_app", key: nil
end
end
```
Expand Down
9 changes: 6 additions & 3 deletions dry-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.6.0"

# to update dependencies edit project.yml
spec.add_runtime_dependency "dry-schema", "~> 1.8"
spec.add_runtime_dependency "dry-system", "~> 0.20.0", ">= 0.18.1"
spec.add_runtime_dependency "dry-validation", "~> 1.7"
spec.add_runtime_dependency "dry-schema", "~> 1.7"
spec.add_runtime_dependency "dry-system", "~> 0.21"
spec.add_runtime_dependency "dry-validation", "~> 1.5"

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"

# our super engine used in specs
spec.add_development_dependency "super_engine"
end
29 changes: 17 additions & 12 deletions lib/dry/rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "dry/rails/railtie"
require "dry/rails/engine"
require "dry/rails/finalizer"
require "dry/rails/container"
require "dry/rails/components"

Expand All @@ -12,22 +14,32 @@ module Dry
#
# Dry::Rails.container do
# config.component_dirs.add "lib" do |dir|
# dir.default_namespace = "my_super_cool_app"
# dir.namespaces.add "my_super_cool_app", key: nil
# end
#
# config.component_dirs.add "app/operations"
# end
#
# @api public
module Rails
extend Configurable
# Set to true to turn off dry-system for main application
# Meant to be used in setup where dry-system is only used within Rails::Engine(s)
#
# @api public
setting :main_app_disabled, default: false

# This is being injected by main app Railtie
# @api private
setting :main_app_name

# Set container block that will be evaluated in the context of the container
#
# @return [self]
#
# @api public
def self.container(&block)
_container_blocks << block
self
Engine.container(config.main_app_name, &block)
end

# Create a new container class
Expand All @@ -40,19 +52,12 @@ def self.container(&block)
#
# @api private
def self.create_container(options = {})
Class.new(Container) { config.update(options) }
Engine.create_container(options)
end

# @api private
def self.evaluate_initializer(container)
_container_blocks.each do |block|
container.class_eval(&block)
end
end

# @api private
def self._container_blocks
@_container_blocks ||= []
Engine.evaluate_initializer(config.main_app_name, container)
end
end
end
2 changes: 1 addition & 1 deletion lib/dry/rails/auto_registrars/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def relative_path(dir, file_path)
path = super
return path unless dir.start_with?("app")

path.split("/")[1..-1].join("/")
path.split("/")[1..].join("/")
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/dry/rails/boot/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
end

start do
ApplicationController.include(Dry::Rails::Features::ControllerHelpers)
unless ApplicationController.include?(Dry::Rails::Features::ControllerHelpers)
ApplicationController.include(Dry::Rails::Features::ControllerHelpers)
end

if defined?(ActionController::API)
if defined?(ActionController::API) &&
!ActionController::API.include?(Dry::Rails::Features::ControllerHelpers)
ActionController::API.include(Dry::Rails::Features::ControllerHelpers)
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/dry/rails/boot/safe_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
end

start do
ApplicationController.include(Dry::Rails::Features::SafeParams)
unless ActionController::Base.include?(Dry::Rails::Features::SafeParams)
ActionController::Base.include(Dry::Rails::Features::SafeParams)
end

if defined?(ActionController::API)
if defined?(ActionController::API) &&
!ActionController::API.include?(Dry::Rails::Features::SafeParams)
ActionController::API.include(Dry::Rails::Features::SafeParams)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/rails/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class << self
#
# TODO: this should be moved to dry-system
def booted?(name)
booter.booted.map(&:identifier).include?(name)
booter.booted.map(&:name).include?(name)
end

# TODO: confirm that this is really needed
Expand Down
44 changes: 44 additions & 0 deletions lib/dry/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

module Dry
module Rails
module Engine
# Set container block that will be evaluated in the context of the container
#
# @param name [Symbol]
# @return [self]
#
# @api public
def self.container(name, &block)
_container_blocks[name] << block
self
end

# Create a new container class
#
# This is used during booting and reloading
#
# @param name [Symbol]
# @param options [Hash] Container configuration settings
#
# @return [Class]
#
# @api private
def self.create_container(options = {})
Class.new(Container) { config.update(options) }
end

# @api private
def self.evaluate_initializer(name, container)
_container_blocks[name].each do |block|
container.class_eval(&block)
end
end

# @api private
def self._container_blocks
@_container_blocks ||= Hash.new { |h, k| h[k] = [] }
end
end
end
end
Loading