lib/micro/case.rb in u-case-3.0.0.rc4 vs lib/micro/case.rb in u-case-3.0.0.rc5
- old
+ new
@@ -16,14 +16,29 @@
require 'micro/cases'
include Micro::Attributes.without(:strict_initialize)
- def self.call(options = {})
+ def self.call(options = Kind::Empty::HASH)
new(options).__call__
end
+ def self.then(use_case = nil, &block)
+ can_yield_self = respond_to?(:yield_self)
+
+ if block
+ raise Error::InvalidInvocationOfTheThenMethod if use_case
+ raise NotImplementedError if !can_yield_self
+
+ yield_self(&block)
+ else
+ return yield_self if !use_case && can_yield_self
+
+ self.call.then(use_case)
+ end
+ end
+
def self.to_proc
Proc.new { |arg| call(arg) }
end
def self.flow(*args)
@@ -83,11 +98,11 @@
self.class_eval('def use_cases; self.class.use_cases; end')
@__flow = __flow_builder__.build(args)
end
- FLOW_STEP = 'Flow_Step'.freeze
+ FLOW_STEP = 'Self'.freeze
private_constant :FLOW_STEP
def self.__call__!
return const_get(FLOW_STEP) if const_defined?(FLOW_STEP, false)
@@ -194,13 +209,9 @@
end
private_constant :MapFailureType
end
- def self.case?(arg)
- (arg.is_a?(Class) && arg < Case) || arg.is_a?(Case)
- end
-
def self.case_or_flow?(arg)
- case?(arg) || arg.is_a?(Cases::Flow)
+ (arg.is_a?(Class) && arg < Case) || arg.is_a?(Cases::Flow)
end
end