Class: ConvenientService::Service::Plugins::HasJSendResultShortSyntax::Success::Commands::RefuteKwargsContainJSendAndExtraKeys

Inherits:
ConvenientService::Support::Command show all
Defined in:
lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/commands/refute_kwargs_contain_j_send_and_extra_keys.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConvenientService::Support::Command

[], call

Constructor Details

#initialize(kwargs:) ⇒ void

Parameters:

  • kwargs (Hash{Symbol => Object})


20
21
22
# File 'lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/commands/refute_kwargs_contain_j_send_and_extra_keys.rb', line 20

def initialize(kwargs:)
  @kwargs = kwargs
end

Instance Attribute Details

#kwargsObject (readonly)

Returns the value of attribute kwargs.



14
15
16
# File 'lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/commands/refute_kwargs_contain_j_send_and_extra_keys.rb', line 14

def kwargs
  @kwargs
end

Instance Method Details

#callvoid

This method returns an undefined value.

Examples:

‘kwargs.keys.difference([:data, :message, :code]).none?`.


{}.keys.difference([:data, :message, :code]).none?
# => true

{a: 1}.keys.difference([:data, :message, :code]).none?
# => false

{data: {}}.keys.difference([:data, :message, :code]).none?
# => true

{data: {}, a: 1}.keys.difference([:data, :message, :code]).none?
# => false

{data: {}, message: ""}.keys.difference([:data, :message, :code]).none?
# => true

{data: {}, message: "", a: 1}.keys.difference([:data, :message, :code]).none?
# => false

{data: {}, message: "", code: :""}.keys.difference([:data, :message, :code]).none?
# => true

{data: {}, message: "", code: :"", a: 1}.keys.difference([:data, :message, :code]).none?
# => false

Raises:



54
55
56
57
58
59
60
# File 'lib/convenient_service/service/plugins/has_j_send_result_short_syntax/success/commands/refute_kwargs_contain_j_send_and_extra_keys.rb', line 54

def call
  return if [:data, :message, :code].none? { |key| kwargs.has_key?(key) }

  return if kwargs.keys.difference([:data, :message, :code]).none?

  ::ConvenientService.raise Exceptions::KwargsContainJSendAndExtraKeys.new
end