lib/micro/service/pipeline.rb in u-service-0.10.0 vs lib/micro/service/pipeline.rb in u-service-0.11.0
- old
+ new
@@ -39,14 +39,21 @@
end
private
def initial_result(arg)
+ return arg.call if arg_to_call?(arg)
return arg if arg.is_a?(Micro::Service::Result)
Micro::Service::Result::Success[value: arg]
end
+
+ def arg_to_call?(arg)
+ return true if arg.is_a?(Micro::Service::Base) || arg.is_a?(Reducer)
+ return true if arg.is_a?(Class) && (arg < Micro::Service::Base || arg < Micro::Service::Pipeline)
+ return false
+ end
end
module ClassMethods
def __pipeline__
@__pipeline
@@ -65,12 +72,22 @@
def self.[](*args)
Reducer.build(args)
end
+ UNDEFINED_PIPELINE = "This class hasn't declared its pipeline. Please, use the `pipeline()` macro to define one.".freeze
+
+ private_constant :UNDEFINED_PIPELINE
+
def self.included(base)
base.extend(ClassMethods)
- base.class_eval('def initialize(options); @options = options; end')
+ base.class_eval(<<-RUBY)
+ def initialize(options)
+ @options = options
+ pipeline = self.class.__pipeline__
+ raise ArgumentError, UNDEFINED_PIPELINE unless pipeline
+ end
+ RUBY
end
def call
self.class.__pipeline__.call(@options)
end