Class: Assertion::Guard
- Inherits:
-
Object
- Object
- Assertion::Guard
- Extended by:
- DSL::Attribute, DSL::Caller
- Defined in:
- lib/assertion/guard.rb
Overview
The base class for object guards
The guard defines a desired state for the object and checks if that state is valid.
Its call method either returns the guarded object, or (when its state is invalid) raises an exception
The class DSL also defines a .[] shortcut to initialize and call the guard for given object immediately.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
The object to be guarded.
Class Method Summary collapse
-
.call ⇒ Object
Validates the state of the [#object] and returns valid object back.
- .initialize(object) ⇒ Object
-
.new(object) ⇒ Assertion::Guard
Creates the guard instance for the provided object.
Methods included from DSL::Attribute
Methods included from DSL::Caller
Instance Attribute Details
#object ⇒ Object (readonly)
Returns The object to be guarded.
42 43 44 |
# File 'lib/assertion/guard.rb', line 42 def object @object end |
Class Method Details
.call ⇒ Object
Validates the state of the [#object] and returns valid object back
64 65 66 67 |
# File 'lib/assertion/guard.rb', line 64 def call state.validate! object end |
.initialize(object) ⇒ Object
53 54 55 56 |
# File 'lib/assertion/guard.rb', line 53 def initialize(object) @object = object IceNine.deep_freeze(self) end |
.new(object) ⇒ Assertion::Guard
Creates the guard instance for the provided object
|
|
# File 'lib/assertion/guard.rb', line 44
|