Class: Yes::Core::Utils::EventNameResolver
- Inherits:
-
Object
- Object
- Yes::Core::Utils::EventNameResolver
- Defined in:
- lib/yes/core/utils/event_name_resolver.rb
Overview
Resolves event names from command names by converting command verbs to their past tense form
Constant Summary collapse
- COMMAND_TO_EVENT_VERBS =
Returns Mapping of command verbs to their corresponding event (past tense) forms.
{ 'Activate' => 'Activated', 'Add' => 'Added', 'Approve' => 'Approved', 'Archive' => 'Archived', 'Assign' => 'Assigned', 'Cancel' => 'Cancelled', 'Change' => 'Changed', 'Close' => 'Closed', 'Complete' => 'Completed', 'Confirm' => 'Confirmed', 'Deactivate' => 'Deactivated', 'Delete' => 'Deleted', 'Disable' => 'Disabled', 'Enable' => 'Enabled', 'Fail' => 'Failed', 'Open' => 'Opened', 'Publish' => 'Published', 'Reactivate' => 'Reactivated', 'Reject' => 'Rejected', 'Remove' => 'Removed', 'Reopen' => 'Reopened', 'Resolve' => 'Resolved', 'Restore' => 'Restored', 'Start' => 'Started', 'Stop' => 'Stopped', 'Submit' => 'Submitted', 'Unassign' => 'Unassigned', 'Unpublish' => 'Unpublished', 'Update' => 'Updated' }.freeze
Class Method Summary collapse
-
.call(command_name) ⇒ Symbol?
Converts a command name to its corresponding event name.
Class Method Details
.call(command_name) ⇒ Symbol?
Converts a command name to its corresponding event name
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yes/core/utils/event_name_resolver.rb', line 51 def self.call(command_name) normalized_command_name = command_name.to_s.camelize COMMAND_TO_EVENT_VERBS.each do |command_verb, event_verb| next unless normalized_command_name.start_with?(command_verb) # Extract the subject (e.g. "Location" from "ChangeLocation") subject = normalized_command_name.delete_prefix(command_verb) # Return subject + verb (e.g. "LocationChanged") return "#{subject}#{event_verb}".underscore.to_sym end nil end |