Class: Solid::Result::Expectations
- Inherits:
-
Object
- Object
- Solid::Result::Expectations
- Defined in:
- lib/solid/result/expectations.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Mixin
Class Method Summary collapse
Instance Method Summary collapse
- #Failure(type, value = nil) ⇒ Object
-
#initialize(source: nil, contract: nil, terminal: nil, **options) ⇒ Expectations
constructor
A new instance of Expectations.
- #Success(type, value = nil) ⇒ Object
- #with(source:, terminal: nil) ⇒ Object
Constructor Details
#initialize(source: nil, contract: nil, terminal: nil, **options) ⇒ Expectations
Returns a new instance of Expectations.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/solid/result/expectations.rb', line 41 def initialize(source: nil, contract: nil, terminal: nil, **) @terminal = terminal @source = source @contract = contract if contract.is_a?(Contract::Evaluator) @contract ||= Contract.new( success: [:success], failure: [:failure], config: [:config] ).freeze end |
Class Method Details
.mixin(**options) ⇒ Object
7 8 9 10 11 |
# File 'lib/solid/result/expectations.rb', line 7 def self.mixin(**) return mixin!(**) if Config.instance.feature.enabled?(:expectations) result_factory_without_expectations.mixin(**.slice(:config)) end |
.new ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/solid/result/expectations.rb', line 31 def self.new(...) return result_factory_without_expectations unless Config.instance.feature.enabled?(:expectations) instance = allocate instance.send(:initialize, ...) instance end |
Instance Method Details
#Failure(type, value = nil) ⇒ Object
59 60 61 |
# File 'lib/solid/result/expectations.rb', line 59 def Failure(type, value = nil) _ResultAs(Failure, type, value) end |
#Success(type, value = nil) ⇒ Object
55 56 57 |
# File 'lib/solid/result/expectations.rb', line 55 def Success(type, value = nil) _ResultAs(Success, type, value) end |
#with(source:, terminal: nil) ⇒ Object
63 64 65 |
# File 'lib/solid/result/expectations.rb', line 63 def with(source:, terminal: nil) self.class.new(source: source, terminal: terminal, contract: contract) end |