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)

Returns the value of attribute result.



27
28
29
# 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 27

def result
  @result
end

#valueObject (readonly)

Returns the value of attribute value.



21
22
23
# 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 21

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


77
78
79
80
81
82
83
84
# 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 77

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:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# 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 124

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.



148
149
150
# 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 148

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

#empty?Boolean

Returns:

  • (Boolean)


54
55
56
# 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 54

def empty?
  value.empty?
end

#has_attribute?(key) ⇒ Boolean

Parameters:

  • key (String, Symbol)

Returns:

  • (Boolean)


62
63
64
# 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 62

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

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

Parameters:



46
47
48
49
# 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 46

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

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


69
70
71
# 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 69

def keys
  value.keys
end

#to_argumentsConveninentService::Support::Arguments

Returns:

  • (ConveninentService::Support::Arguments)


162
163
164
# 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 162

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

#to_hHash

Returns:

  • (Hash)


169
170
171
# 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 to_h
  @to_h ||= value.to_h
end

#to_kwargsHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


155
156
157
# 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 155

def to_kwargs
  to_arguments.kwargs
end

#to_sString

Returns:

  • (String)


176
177
178
# 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 176

def to_s
  @to_s ||= to_h.to_s
end