Class: WinewooCore::UseCases::UseCaseResults

Inherits:
Object
  • Object
show all
Defined in:
lib/winewoo_core/use_cases/use_case_results.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, resource = nil) ⇒ UseCaseResults

Returns a new instance of UseCaseResults.



20
21
22
23
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 20

def initialize(result, resource = nil)
  @result = result
  @resource = resource
end

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



17
18
19
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 17

def meta
  @meta
end

#resourceObject

Returns the value of attribute resource.



15
16
17
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 15

def resource
  @resource
end

#resultObject

Returns the value of attribute result.



16
17
18
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 16

def result
  @result
end

Class Method Details

.failure(resource = nil) ⇒ Object



10
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 10

def self.failure(resource = nil) new(:failure, resource) end

.found(resource, meta = nil) ⇒ Object



4
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 4

def self.found(resource, meta = nil) new(:found, resource).tap {|i| i.meta = meta} end

.not_foundObject



6
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 6

def self.not_found() new(:not_found) end

.success(resource = nil) ⇒ Object



8
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 8

def self.success(resource = nil) new(:success, resource) end

.unauthorized(resource = nil) ⇒ Object



12
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 12

def self.unauthorized(resource = nil) new(:unauthorized, resource) end

Instance Method Details

#on_failureObject



52
53
54
55
56
57
58
59
60
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 52

def on_failure
  if @result == :failure
    if @resource
      yield @resource
    else
      yield
    end
  end
end

#on_found {|resource, meta| ... } ⇒ Object

Yields:



26
27
28
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 26

def on_found
  yield resource, meta if @result == :found
end

#on_not_foundObject



31
32
33
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 31

def on_not_found
  yield if @result == :not_found
end

#on_successObject



41
42
43
44
45
46
47
48
49
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 41

def on_success
  if @result == :success
    if @resource
      yield @resource
    else
      yield
    end
  end
end

#on_unauthorizedObject



36
37
38
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 36

def on_unauthorized
  yield if @result == :unauthorized
end