Module: ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Concern::InstanceMethods

Includes:
ConvenientService::Support::Copyable, ConvenientService::Support::Delegate
Defined in:
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb

Overview

TODO: How to use concern outside?

Instance Method Summary collapse

Methods included from ConvenientService::Support::Copyable

#copy

Methods included from ConvenientService::Support::Concern

included

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

Returns:

  • (Boolean, nil)


136
137
138
139
140
141
142
143
144
145
146
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 136

def ==(other)
  return unless other.instance_of?(self.class)

  return false if service.class != other.service.class
  return false if status != other.status
  return false if unsafe_data != other.unsafe_data
  return false if unsafe_message != other.unsafe_message
  return false if unsafe_code != other.unsafe_code

  true
end

#codeConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code Also known as: unsafe_code



82
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 82

delegate :code, to: :jsend_attributes

#create_code(code) ⇒ Symbol

Returns:

  • (Symbol)


125
126
127
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 125

def create_code(code)
  self.class.code(value: code, result: self)
end

#create_data(data) ⇒ Hash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


111
112
113
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 111

def create_data(data)
  self.class.data(value: data, result: self)
end

#create_message(message) ⇒ String

Returns:

  • (String)


118
119
120
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 118

def create_message(message)
  self.class.message(value: message, result: self)
end

#create_status(status) ⇒ Symbol

Returns:

  • (Symbol)


104
105
106
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 104

def create_status(status)
  self.class.status(value: status, result: self)
end

#dataConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Data Also known as: unsafe_data



62
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 62

delegate :data, to: :jsend_attributes

#error?Boolean

Returns:

  • (Boolean)


32
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 32

delegate :error?, to: :status

#extra_kwargsHash{Object => Symbol}

Returns:

  • (Hash{Object => Symbol})


92
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 92

delegate :extra_kwargs, to: :jsend_attributes

#failure?Boolean

Returns:

  • (Boolean)


27
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 27

delegate :failure?, to: :status

#jsend_attributesConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Structs::JSendAttributes



97
98
99
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 97

def jsend_attributes
  internals.cache[:jsend_attributes]
end

#messageConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message Also known as: unsafe_message



72
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 72

delegate :message, to: :jsend_attributes

#not_error?Boolean

Returns:

  • (Boolean)


47
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 47

delegate :not_error?, to: :status

#not_failure?Boolean

Returns:

  • (Boolean)


42
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 42

delegate :not_failure?, to: :status

#not_success?Boolean

Returns:

  • (Boolean)


37
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 37

delegate :not_success?, to: :status

#serviceClass

Returns:

  • (Class)


52
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 52

delegate :service, to: :jsend_attributes

#statusConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status



57
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 57

delegate :status, to: :jsend_attributes

#success?Boolean

Returns:

  • (Boolean)


22
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 22

delegate :success?, to: :status

#to_aArray<ConvenientService::Support::Value>

Note:

This method is useful for learning purposes, to show similarities with Ruby’s objects. Please, do NOT depend on it in production.

Returns an array representation of ‘result`. `success` may be considered as array with items. `failure` may be considered as empty array. `error` may be considered as `raise exception`.

Returns:

Raises:

  • (ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation)


240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 240

def to_a
  case status.value
  when :success
    [Support::Value.new("item")]
  when :failure
    []
  when :error
    raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :array)
  else
    raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
  end
end

#to_argumentsConveninentService::Support::Arguments

Returns:

  • (ConveninentService::Support::Arguments)


158
159
160
161
162
163
164
165
166
167
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 158

def to_arguments
  Support::Arguments.new(
    service: service,
    status: status,
    data: unsafe_data,
    message: unsafe_message,
    code: unsafe_code,
    **extra_kwargs
  )
end

#to_boolBoolean

Note:

This method is useful for learning purposes, to show similarities with Ruby’s booleans. Please, do NOT depend on it in production.

Returns a boolean representation of ‘result`. `success` may be considered as `true`. `failure` may be considered as `false`. `error` may be considered as `raise exception`.

Returns:

  • (Boolean)

Raises:

  • (ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation)


184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 184

def to_bool
  case status.value
  when :success
    true
  when :failure
    false
  when :error
    raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :boolean)
  else
    raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
  end
end

#to_hHash{ConvenientService::Support::Value => ConvenientService::Support::Value}

Note:

This method is useful for learning purposes, to show similarities with Ruby’s objects. Please, do NOT depend on it in production.

Returns a hash representation of ‘result`. `success` may be considered as hash with items. `failure` may be considered as empty hash. `error` may be considered as `raise exception`.

Returns:

Raises:

  • (ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation)


268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 268

def to_h
  case status.value
  when :success
    {Support::Value.new("key") => Support::Value.new("value")}
  when :failure
    {}
  when :error
    raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :hash)
  else
    raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
  end
end

#to_kwargsHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


151
152
153
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 151

def to_kwargs
  to_arguments.kwargs
end

#to_objectConvenientService::Support::Value

Note:

This method is useful for learning purposes, to show similarities with Ruby’s objects. Please, do NOT depend on it in production.

Returns a boolean representation of ‘result`. `success` may be considered as `object`. `failure` may be considered as `nil` (or null object). `error` may be considered as `raise exception`.

Returns:

Raises:

  • (ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation)


212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 212

def to_object
  case status.value
  when :success
    Support::Value.new("object")
  when :failure
    nil
  when :error
    raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :object)
  else
    raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
  end
end

#to_sString

Note:

This method is useful for learning purposes, to show similarities with Ruby’s objects. Please, do NOT depend on it in production.

Returns a string representation of ‘result`. `success` may be considered as string with content. `failure` may be considered as empty string. `error` may be considered as `raise exception`.

Returns:

  • (String)

Raises:

  • (ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation)


296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb', line 296

def to_s
  case status.value
  when :success
    "string"
  when :failure
    ""
  when :error
    raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :string)
  else
    raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
  end
end