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

Defined in:
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#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)


84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb', line 84

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_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)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb', line 28

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)


112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb', line 112

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_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)


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb', line 56

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)


140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb', line 140

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