lib/bcdd/result/expectations.rb in bcdd-result-0.6.0 vs lib/bcdd/result/expectations.rb in bcdd-result-0.7.0

- old
+ new

@@ -1,50 +1,41 @@ # frozen_string_literal: true -class BCDD::Result::Expectations - require_relative 'expectations/mixin' - require_relative 'expectations/error' - require_relative 'expectations/contract' - require_relative 'expectations/type_checker' +class BCDD::Result + class Expectations + require_relative 'expectations/mixin' - def self.mixin(success: nil, failure: nil, with: nil) - addons = Mixin::Addons.options(with) + def self.mixin(success: nil, failure: nil, with: nil) + addons = Mixin::Addons.options(with) - mod = Module.new - mod.const_set(:Expected, new(success: success, failure: failure).freeze) - mod.module_eval(Mixin::METHODS) - mod.send(:include, *addons) unless addons.empty? - mod - end + mod = Mixin.module! + mod.const_set(:Result, new(success: success, failure: failure).freeze) + mod.module_eval(Mixin::METHODS) + mod.send(:include, *addons) unless addons.empty? + mod + end - def self.evaluate(data, expectations) - expectations ||= Contract::NONE + def initialize(subject: nil, success: nil, failure: nil, contract: nil) + @subject = subject - expectations.type_and_value!(data) + @contract = contract if contract.is_a?(Contract::Evaluator) - TypeChecker.new(data.type, expectations: expectations) - end + @contract ||= Contract.new(success: success, failure: failure).freeze + end - def initialize(subject: nil, success: nil, failure: nil, contract: nil) - @subject = subject + def Success(type, value = nil) + Success.new(type: type, value: value, subject: subject, expectations: contract) + end - @contract = contract if contract.is_a?(Contract::Evaluator) + def Failure(type, value = nil) + Failure.new(type: type, value: value, subject: subject, expectations: contract) + end - @contract ||= Contract.new(success: success, failure: failure).freeze - end + def with(subject:) + self.class.new(subject: subject, contract: contract) + end - def Success(type, value = nil) - ::BCDD::Result::Success.new(type: type, value: value, subject: subject, expectations: contract) - end + private - def Failure(type, value = nil) - ::BCDD::Result::Failure.new(type: type, value: value, subject: subject, expectations: contract) + attr_reader :subject, :contract end - - def with(subject:) - self.class.new(subject: subject, contract: contract) - end - - private - - attr_reader :subject, :contract end