Class: 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.



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

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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

Class Method Details

.failure(error: {}) ⇒ Object



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

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

.success(data: {}) ⇒ Object



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

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

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


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

def failure?
  !@success
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  @success
end