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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConvenientService::Support::Copyable

#copy

Instance Attribute Details

#resultObject (readonly) Also known as: __result__



43
44
45
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 43

def result
  @result
end

#valueObject (readonly) Also known as: __value__



29
30
31
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 29

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


122
123
124
125
126
127
128
129
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 122

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

  return false if __result__.class != other.__result__.class
  return false if __value__ != other.__value__

  true
end

#===(other) ⇒ Boolean?

Note:

Data#=== allows to use RSpec expectation matchers and RSpec mocks arguments matchers for comparison.

Examples:

RSpec expectation matchers.

expect(result).to be_success.with_data(foo: match(/bar/))

RSpec mocks arguments matchers.

expect(result).to be_success.with_data(hash_including(:foo))

Combo of RSpec expectation matchers and RSpec mocks arguments.

expect(result).to be_success.with_data(hash_including(foo: match(/bar/)))

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)

See Also:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 169

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

  return false if __result__.class != other.__result__.class

  ##
  # NOTE: Pattern matching is removed since it causes a huge and annoying warning in Ruby 2.7 apps. Users are too confused by it.
  #
  # TODO: Implement a Rubocop cop that forbids the usage of pattern matching until Ruby 2.7 is dropped.
  #
  if __value__.instance_of?(::Hash) && other.__value__.instance_of?(::Hash)
    return false unless Utils::Hash.triple_equality_compare(__value__, other.__value__)
  else
    return false unless __value__ === other.__value__
  end

  true
end

#[](key) ⇒ Object

Returns Can be any type.



193
194
195
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 193

def [](key)
  __value__.fetch(key.to_sym) { ::ConvenientService.raise Exceptions::NotExistingAttribute.new(attribute: key) }
end

#empty?Boolean Also known as: __empty__?

Returns:

  • (Boolean)


78
79
80
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 78

def empty?
  __value__.empty?
end

#has_attribute?(key) ⇒ Boolean Also known as: __has_attribute__?

Parameters:

  • key (String, Symbol)

Returns:

  • (Boolean)


94
95
96
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 94

def has_attribute?(key)
  __value__.has_key?(key.to_sym)
end

#initialize(value:, result: nil) ⇒ void

Parameters:



67
68
69
70
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 67

def initialize(value:, result: nil)
  @value = value
  @result = result
end

#keysArray<Symbol> Also known as: __keys__

Returns:

  • (Array<Symbol>)


109
110
111
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 109

def keys
  __value__.keys
end

#to_argumentsConveninentService::Support::Arguments

Returns:

  • (ConveninentService::Support::Arguments)


207
208
209
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 207

def to_arguments
  @to_arguments ||= Support::Arguments.new(value: __value__, result: __result__)
end

#to_hHash

Returns:

  • (Hash)


214
215
216
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 214

def to_h
  @to_h ||= __value__.to_h
end

#to_kwargsHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


200
201
202
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 200

def to_kwargs
  to_arguments.kwargs
end

#to_sString

Returns:

  • (String)


221
222
223
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb', line 221

def to_s
  @to_s ||= to_h.to_s
end