Exception: ConvenientService::Service::Plugins::HasJSendResultShortSyntax::Exceptions::KwargsContainJSendAndExtraKeys

Inherits:
Exception
  • Object
show all
Defined in:
lib/convenient_service/service/plugins/has_j_send_result_short_syntax/exceptions.rb

Instance Method Summary collapse

Methods inherited from Exception

new

Instance Method Details

#initialize_with_kwargs(status:) ⇒ void

This method returns an undefined value.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/convenient_service/service/plugins/has_j_send_result_short_syntax/exceptions.rb', line 17

def initialize_with_kwargs(status:)
  message = <<~TEXT
    `kwargs` passed to `#{status}` method contain JSend keys and extra keys. That's NOT allowed.

    Please, consider something like:

    # Shorter form. Assumes that all kwargs are `data`.
    #{status}(foo: :bar)

    # Shorter form with one arg. Assumes that arg is `message`.
    #{status}("foo")

    # Shorter form with two args. Assumes that first arg is `message` and second is `code`.
    #{status}("foo", :foo)

    # Longer form. More explicit `data`.
    #{status}(data: {foo: :bar})

    # Longer form. More explicit `message`.
    #{status}(message: "foo")

    # Longer form. More explicit `code`.
    #{status}(code: :foo)

    # Longer form. More explicit `message` and `code` together.
    #{status}(message: "foo", code: :foo)

    # (Advanced) Longer form also supports any other variation of `data`, `message` and `code`.
    #{status}(data: {foo: :bar}, message: "foo")
    #{status}(data: {foo: :bar}, code: :foo)
    #{status}(data: {foo: :bar}, message: "foo", code: :foo)
  TEXT

  initialize(message)
end