Skip to content

Commit

Permalink
feat: Allow to skip extends loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Jun 6, 2024
1 parent c92eaa1 commit 600c72a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ And then execute:
bundle
```

## Configure Emitter

Configuration allows to skip extends made by the module using initializer

Create `config/initializers/decidim_emitter.rb` and add the following:

```ruby
# frozen_string_literal: true

Decidim::Emitter.configure do |config|
config.exclude_extends = [:participatory_process, :participatory_process_form, :participatory_process_create, :participatory_process_copy, :participatory_process_update]
end
```


## Next improvements

- Move emitter to a dedicated model and use a DB relation to link it to Participatory Processes
Expand Down
11 changes: 11 additions & 0 deletions lib/decidim/emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@ module Decidim
# This namespace holds the logic of the `Emitter` component. This component
# allows users to create emitter in a participatory space.
module Emitter
include ActiveSupport::Configurable

# Public: The configuration to exclude extends from the engine.
# [:participatory_process, :participatory_process_form, :participatory_process_create, :participatory_process_copy, :participatory_process_update]
config_accessor :exclude_extends do
[]
end

def self.skip_extend?(extend_sym)
extend_sym.in?(exclude_extends)
end
end
end
18 changes: 13 additions & 5 deletions lib/decidim/emitter/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ class Engine < ::Rails::Engine

initializer "decidim.emitter.overrides" do
config.to_prepare do
Decidim::ParticipatoryProcess.include Decidim::Emitter::ParticipatoryProcessOverride
Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessForm.include Decidim::Emitter::Admin::ParticipatoryProcessFormOverride
Decidim::ParticipatoryProcesses::Admin::CreateParticipatoryProcess.include Decidim::Emitter::ParticipatoryProcesses::Admin::CreateParticipatoryProcessOverride
Decidim::ParticipatoryProcesses::Admin::CopyParticipatoryProcess.include Decidim::Emitter::ParticipatoryProcesses::Admin::CopyParticipatoryProcessOverride
Decidim::ParticipatoryProcesses::Admin::UpdateParticipatoryProcess.include Decidim::Emitter::ParticipatoryProcesses::Admin::UpdateParticipatoryProcessOverride
Decidim::ParticipatoryProcess.include(Decidim::Emitter::ParticipatoryProcessOverride) unless Decidim::Emitter.skip_extend?(:participatory_process)
unless Decidim::Emitter.skip_extend?(:participatory_process_form)
Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessForm.include(Decidim::Emitter::Admin::ParticipatoryProcessFormOverride)
end
unless Decidim::Emitter.skip_extend?(:participatory_process_create)
Decidim::ParticipatoryProcesses::Admin::CreateParticipatoryProcess.include(Decidim::Emitter::ParticipatoryProcesses::Admin::CreateParticipatoryProcessOverride)
end
unless Decidim::Emitter.skip_extend?(:participatory_process_copy)
Decidim::ParticipatoryProcesses::Admin::CopyParticipatoryProcess.include(Decidim::Emitter::ParticipatoryProcesses::Admin::CopyParticipatoryProcessOverride)
end
unless Decidim::Emitter.skip_extend?(:participatory_process_update)
Decidim::ParticipatoryProcesses::Admin::UpdateParticipatoryProcess.include(Decidim::Emitter::ParticipatoryProcesses::Admin::UpdateParticipatoryProcessOverride)
end
end
end
end
Expand Down

0 comments on commit 600c72a

Please sign in to comment.