Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ActiveDryDeps.configure #2

Merged
merged 1 commit into from
Nov 18, 2024
Merged
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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ end
gem auto-configuring, but you can override settings

```ruby
ActiveDryDeps.config.container = 'MyApp::Container'
ActiveDryDeps.config.inflector = ActiveSupport::Inflector
ActiveDryDeps.config.inject_global_constant = 'Deps'
# config/initializers/active_dry_deps.rb
ActiveDryDeps.configure do |config|
config.container = 'MyApp::Container'
config.inflector = ActiveSupport::Inflector
config.inject_global_constant = 'Deps'
end
```

### Recommended container setup with [dry-system](https://dry-rb.org/gems/dry-system/) for Rails
Expand Down
8 changes: 5 additions & 3 deletions lib/active_dry_deps.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require_relative 'active_dry_deps/version'
require_relative 'active_dry_deps/configuration'
require_relative 'active_dry_deps/railtie'
require 'active_dry_deps/version'
require 'active_dry_deps/configuration'
require 'active_dry_deps/railtie'

module ActiveDryDeps

autoload :Deps, 'active_dry_deps/deps'

class Error < StandardError; end
class DependencyNameInvalid < Error; end

Expand Down
4 changes: 1 addition & 3 deletions lib/active_dry_deps/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
module ActiveDryDeps
class Railtie < ::Rails::Railtie

config.before_initialize do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot modify frozen config (Dry::Configurable::FrozenConfigError)

config.to_prepare do
app_namespace = ::Rails.application.class.to_s.split('::').first
ActiveDryDeps.config.container ||= "#{app_namespace}::Container"

require_relative 'deps'

Object.const_set(ActiveDryDeps.config.inject_global_constant, ::ActiveDryDeps::Deps)
ActiveDryDeps.config.finalize!(freeze_values: true)
end
Expand Down
Loading