Class: SolidObjects::OperationDispatcher
- Inherits:
-
Object
- Object
- SolidObjects::OperationDispatcher
- Defined in:
- lib/solid_objects/operation_dispatcher.rb,
sig/generated/lib/solid_objects/operation_dispatcher.rbs
Constant Summary collapse
- RESERVED_REFERENCE_METHOD_NAMES =
%i[actor_type actor_id async sync destroy snapshot].freeze
- RESERVED_OPERATION_NAMES =
( public_instance_methods(true) + RESERVED_REFERENCE_METHOD_NAMES ).map(&:to_sym).uniq.freeze
Instance Attribute Summary collapse
-
#actor_type ⇒ Object
readonly
Returns the value of attribute actor_type.
-
#dispatch ⇒ Object
readonly
Returns the value of attribute dispatch.
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(actor_type:, handlers:) {|arg0, arg1| ... } ⇒ OperationDispatcher
constructor
A new instance of OperationDispatcher.
- #method_missing(name, *arguments, **keywords, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(actor_type:, handlers:) {|arg0, arg1| ... } ⇒ OperationDispatcher
Returns a new instance of OperationDispatcher.
10 11 12 13 14 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 10 def initialize(actor_type:, handlers:, &dispatch) @actor_type = actor_type @handlers = handlers.dup.freeze @dispatch = dispatch end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, **keywords, &block) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 17 def method_missing(name, *arguments, **keywords, &block) raise UnknownMessage, "unknown message #{name.inspect} for #{actor_type}" unless handlers.key?(name) if arguments.any? || block raise ArgumentError, "actor operations accept keyword arguments only" end dispatch.call(name, keywords) end |
Instance Attribute Details
#actor_type ⇒ Object (readonly)
Returns the value of attribute actor_type.
33 34 35 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 33 def actor_type @actor_type end |
#dispatch ⇒ Object (readonly)
Returns the value of attribute dispatch.
33 34 35 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 33 def dispatch @dispatch end |
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
33 34 35 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 33 def handlers @handlers end |
Class Method Details
.validate_operation_name!(name) ⇒ void
This method returns an undefined value.
43 44 45 46 47 48 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 43 def validate_operation_name!(name) operation_name = name.to_sym return unless RESERVED_OPERATION_NAMES.include?(operation_name) raise InvalidActor, "#{operation_name.inspect} conflicts with actor dispatch" end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
27 28 29 |
# File 'lib/solid_objects/operation_dispatcher.rb', line 27 def respond_to_missing?(name, include_private = false) handlers.key?(name) || super end |