Module: ServiceActor::ArgumentsValidator

Defined in:
lib/service_actor/arguments_validator.rb

Class Method Summary collapse

Class Method Details

.validate_default_value(value, origin_type:, origin_name:, actor:) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/service_actor/arguments_validator.rb', line 23

def validate_default_value(value, origin_type:, origin_name:, actor:)
  return if value.is_a?(Proc) || !defined?(Ractor.shareable?) || Ractor.shareable?(value)

  ::Kernel.warn(
    "DEPRECATED: Actor `#{actor}` has #{origin_type} `#{origin_name}` with default " \
      "which is not a Proc or an immutable object.",
  )
end

.validate_error_class(value) ⇒ Object

Raises:



17
18
19
20
21
# File 'lib/service_actor/arguments_validator.rb', line 17

def validate_error_class(value)
  return if value.is_a?(Class) && value <= Exception

  raise ArgumentError, "Expected #{value} to be a subclass of Exception"
end

.validate_origin_name(name, origin:) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
# File 'lib/service_actor/arguments_validator.rb', line 6

def validate_origin_name(name, origin:)
  name = name.to_sym
  return if name == :error

  methods = ServiceActor::Core.instance_methods + ServiceActor::Result.instance_methods
  return unless methods.include?(name)

  raise ArgumentError,
        "#{origin} `#{name}` overrides `ServiceActor::Result` instance method"
end