Class: Solid::Result::Expectations

Inherits:
Object
  • Object
show all
Defined in:
lib/solid/result/expectations.rb

Direct Known Subclasses

Output::Expectations

Defined Under Namespace

Modules: Mixin

Class Method Summary collapse

Instance Method Summary collapse

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, **options)
  @terminal = terminal

  @source = source

  @contract = contract if contract.is_a?(Contract::Evaluator)

  @contract ||= Contract.new(
    success: options[:success],
    failure: options[:failure],
    config: options[: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(**options)
  return mixin!(**options) if Config.instance.feature.enabled?(:expectations)

  result_factory_without_expectations.mixin(**options.slice(:config))
end

.newObject



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