Class: WolfCore::Result

Inherits:
Object show all
Defined in:
lib/wolf_core/utils/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, data: nil, error: nil) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
# File 'lib/wolf_core/utils/result.rb', line 5

def initialize(success:, data: nil, error: nil)
  @success = success
  @data = data
  @error = error
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/wolf_core/utils/result.rb', line 3

def data
  @data
end

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/wolf_core/utils/result.rb', line 3

def error
  @error
end

Class Method Details

.failure(error: {}) ⇒ Object



15
16
17
# File 'lib/wolf_core/utils/result.rb', line 15

def self.failure(error: {})
  Result.new(success: false, error: OpenStruct.new(error))
end

.success(data: {}) ⇒ Object



11
12
13
# File 'lib/wolf_core/utils/result.rb', line 11

def self.success(data: {})
  Result.new(success: true, data: OpenStruct.new(data))
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/wolf_core/utils/result.rb', line 23

def failure?
  !@success
end

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/wolf_core/utils/result.rb', line 19

def success?
  @success
end