Module: Resulting::Resultable

Included in:
Result
Defined in:
lib/resulting/resultable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/resulting/resultable.rb', line 3

def self.included(base)
  base.extend ClassMethods
  attr_reader :success, :value
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/resulting/resultable.rb', line 17

def failure?
  !@success
end

#initialize(success, value) ⇒ Object



8
9
10
11
# File 'lib/resulting/resultable.rb', line 8

def initialize(success, value)
  @success = success
  @value = value.is_a?(Resulting::Resultable) ? value.value : value
end

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/resulting/resultable.rb', line 13

def success?
  @success
end

#valuesObject



21
22
23
24
25
26
27
# File 'lib/resulting/resultable.rb', line 21

def values
  if value.is_a?(Hash)
    value.values.flatten
  else
    Array(value).flatten
  end
end