Class: Decidim::Command
- Inherits:
-
Object
show all
- Includes:
- Wisper::Publisher
- Defined in:
- lib/decidim/command.rb
Direct Known Subclasses
Amendable::Accept, Amendable::CreateDraft, Amendable::DestroyDraft, Amendable::Promote, Amendable::PublishDraft, Amendable::Reject, Amendable::UpdateDraft, Amendable::Withdraw, Decidim::Commands::CreateResource, Decidim::Commands::DestroyResource, Decidim::Commands::RestoreResource, Decidim::Commands::SoftDeleteResource, Decidim::Commands::UpdateResource, CreateEditorImage, CreateEphemeralUser, CreateFollow, CreateOmniauthRegistration, CreateRegistration, CreateReport, CreateUserReport, DeleteFollow, DestroyAccount, DestroyEphemeralUser, InviteUser, InviteUserAgain, LikeResource, Messaging::ReplyToConversation, Messaging::StartConversation, ResendConfirmationInstructions, Search, UnlikeResource, UnsubscribeSettings, UpdateAccount, UpdateNotificationsSettings, UpdatePassword, UpdateResourcesTaxonomies, ValidateUpload
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/decidim/command.rb', line 34
def method_missing(method_name, ...)
if @caller.respond_to?(method_name, true)
@caller.send(method_name, ...)
else
super
end
end
|
Class Method Details
.call ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/decidim/command.rb', line 14
def self.call(*, **, &)
event_recorder = Decidim::EventRecorder.new
command = new(*, **)
command.subscribe(event_recorder)
command.evaluate(&) if block_given?
command.call
event_recorder.events
end
|
Instance Method Details
#evaluate(&block) ⇒ Object
25
26
27
28
|
# File 'lib/decidim/command.rb', line 25
def evaluate(&block)
@caller = block.binding.receiver
instance_eval(&block)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
42
43
44
|
# File 'lib/decidim/command.rb', line 42
def respond_to_missing?(method_name, include_private = false)
@caller.respond_to?(method_name, include_private)
end
|
#transaction ⇒ Object
30
31
32
|
# File 'lib/decidim/command.rb', line 30
def transaction(&)
ActiveRecord::Base.transaction(&) if block_given?
end
|
#with_events(with_transaction: false) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/decidim/command.rb', line 46
def with_events(with_transaction: false, &)
ActiveSupport::Notifications.publish("#{event_namespace}:before", **event_arguments)
with_transaction ? transaction(&) : yield
ActiveSupport::Notifications.publish("#{event_namespace}:after", **event_arguments)
end
|