Class: LunaPark::UseCases::Scenario
- Inherits:
-
Object
- Object
- LunaPark::UseCases::Scenario
- Extended by:
- Extensions::Callable
- Includes:
- Extensions::Attributable, Extensions::HasErrors
- Defined in:
- lib/luna_park/use_cases/scenario.rb
Overview
The main goal of the use case is a high-level description of the business process. This specific implementation is based on the ideas of Ivar Jacobson from his article Ivar Jacobson: Use Case 2.0.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The result obtained during the execution of the scenario.
-
#failure ⇒ Object
readonly
If a failure occurs during the scenario, then this attribute will contain this error Else it’s nil.
-
#locale ⇒ Object
readonly
Current locale.
-
#state ⇒ Object
readonly
What status is the process of doing the work under the scenario.
Class Method Summary collapse
-
.default_notifier ⇒ Object
Default notifier.
-
.notify_with(notifier) ⇒ Object
Set notifier for this class.
Instance Method Summary collapse
-
#call ⇒ Object
abstract
You must define this action and describe all business logic here.
- #call! ⇒ Object
-
#fail? ⇒ Boolean
(also: #failure?, #failed?)
True if the scenario runs unsuccessfully.
-
#failure_message(locale: nil) ⇒ String
Fail message.
-
#initialize(notifier: nil, locale: nil, **attrs) ⇒ Scenario
constructor
Initialize new scenario.
-
#notifier ⇒ Object
Return notifier.
-
#perform ⇒ Object
abstract
You must define this action and describe all business logic here.
-
#success? ⇒ Boolean
(also: #succeed?)
True if the scenario runs successfully.
Methods included from Extensions::HasErrors
Constructor Details
#initialize(notifier: nil, locale: nil, **attrs) ⇒ Scenario
Initialize new scenario
153 154 155 156 157 158 159 160 |
# File 'lib/luna_park/use_cases/scenario.rb', line 153 def initialize(notifier: nil, locale: nil, **attrs) set_attributes attrs @data = nil @failure = nil @locale = locale @notifier = notifier @state = INIT end |
Instance Attribute Details
#data ⇒ Object (readonly)
The result obtained during the execution of the scenario. It’s nil on failure scenario.
119 120 121 |
# File 'lib/luna_park/use_cases/scenario.rb', line 119 def data @data end |
#failure ⇒ Object (readonly)
If a failure occurs during the scenario, then this attribute will contain this error Else it’s nil.
96 97 98 |
# File 'lib/luna_park/use_cases/scenario.rb', line 96 def failure @failure end |
#locale ⇒ Object (readonly)
Current locale
122 123 124 |
# File 'lib/luna_park/use_cases/scenario.rb', line 122 def locale @locale end |
#state ⇒ Object (readonly)
What status is the process of doing the work under the scenario. It can be :initialized, :success, :failure
71 72 73 |
# File 'lib/luna_park/use_cases/scenario.rb', line 71 def state @state end |
Class Method Details
.default_notifier ⇒ Object
Returns Default notifier.
275 276 277 |
# File 'lib/luna_park/use_cases/scenario.rb', line 275 def default_notifier @default_notifier ||= DEFAULT_NOTIFIER end |
.notify_with(notifier) ⇒ Object
Set notifier for this class
292 293 294 |
# File 'lib/luna_park/use_cases/scenario.rb', line 292 def notify_with(notifier) @default_notifier = notifier end |
Instance Method Details
#call ⇒ Object
You must define this action and describe all business logic here. When you run this method - it run as is, and does not change scenario instance.
243 244 245 246 |
# File 'lib/luna_park/use_cases/scenario.rb', line 243 def call rescue_exception { @data = call! } self end |
#call! ⇒ Object
162 163 164 |
# File 'lib/luna_park/use_cases/scenario.rb', line 162 def call! perform end |
#fail? ⇒ Boolean Also known as: failure?, failed?
Returns true if the scenario runs unsuccessfully.
254 255 256 |
# File 'lib/luna_park/use_cases/scenario.rb', line 254 def fail? state == FAIL end |
#failure_message(locale: nil) ⇒ String
Returns fail message.
269 270 271 |
# File 'lib/luna_park/use_cases/scenario.rb', line 269 def (locale: nil) failure&.(locale: locale || self.locale) end |
#notifier ⇒ Object
Return notifier
249 250 251 |
# File 'lib/luna_park/use_cases/scenario.rb', line 249 def notifier @notifier ||= self.class.default_notifier end |
#perform ⇒ Object
You must define this action and describe all business logic here. When you run this method - it run as is, and does not change scenario instance.
199 200 201 |
# File 'lib/luna_park/use_cases/scenario.rb', line 199 def perform raise Errors::AbstractMethod end |
#success? ⇒ Boolean Also known as: succeed?
Returns true if the scenario runs successfully.
262 263 264 |
# File 'lib/luna_park/use_cases/scenario.rb', line 262 def success? state == SUCCESS end |