Class: WinewooCore::UseCases::UseCaseResults
- Inherits:
-
Object
- Object
- WinewooCore::UseCases::UseCaseResults
- Defined in:
- lib/winewoo_core/use_cases/use_case_results.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
- .failure(resource = nil) ⇒ Object
- .found(resource, meta = nil) ⇒ Object
- .not_found ⇒ Object
- .success(resource = nil) ⇒ Object
- .unauthorized(resource = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(result, resource = nil) ⇒ UseCaseResults
constructor
A new instance of UseCaseResults.
- #on_failure ⇒ Object
- #on_found {|resource, meta| ... } ⇒ Object
- #on_not_found ⇒ Object
- #on_success ⇒ Object
- #on_unauthorized ⇒ Object
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
#meta ⇒ Object
Returns the value of attribute meta.
17 18 19 |
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 17 def @meta end |
#resource ⇒ Object
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 |
#result ⇒ Object
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, = nil) new(:found, resource).tap {|i| i. = } end |
.not_found ⇒ Object
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.(resource = nil) new(:unauthorized, resource) end |
Instance Method Details
#on_failure ⇒ Object
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
26 27 28 |
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 26 def on_found yield resource, if @result == :found end |
#on_not_found ⇒ Object
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_success ⇒ Object
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_unauthorized ⇒ Object
36 37 38 |
# File 'lib/winewoo_core/use_cases/use_case_results.rb', line 36 def yield if @result == :unauthorized end |