lib/trailblazer/operation/pipetree.rb in trailblazer-operation-0.0.7 vs lib/trailblazer/operation/pipetree.rb in trailblazer-operation-0.0.8

- old
+ new

@@ -1,10 +1,16 @@ require "pipetree" require "pipetree/flow" require "trailblazer/operation/result" require "uber/option" +if RUBY_VERSION == "1.9.3" + require "trailblazer/operation/1.9.3/option" # TODO: rename to something better. +else + require "trailblazer/operation/option" # TODO: rename to something better. +end + class Trailblazer::Operation New = ->(klass, options) { klass.new(options) } # returns operation instance. # Implements the API to populate the operation's pipetree and # `Operation::call` to invoke the latter. @@ -64,42 +70,19 @@ heritage.record(:_insert, operator, proc, options) DSL.insert(self["pipetree"], operator, proc, options, definer_name: self.name) end - # :private: - module Option - def self.call(proc, &block) - type = :proc - - option = - if proc.is_a? Symbol - type = :symbol - ->(input, *_options) { input.send(proc, *_options) } - elsif proc.is_a? Proc - # ->(input, options) { proc.(**options) } - ->(input, *_options) { proc.(*_options) } - elsif proc.is_a? Uber::Callable - type = :callable - ->(input, *_options) { proc.(*_options) } - end - - yield type if block_given? - option - end - end - # :public: # Wrap the step into a proc that only passes `options` to the step. # This is pure convenience for the developer and will be the default # API for steps. ATM, we also automatically generate a step `:name`. def self.insert(pipe, operator, proc, options={}, kws={}) # TODO: definer_name is a hack for debugging, only. - # proc = Uber::Option[proc] _proc = if options[:wrap] == false proc else - Option.(proc) do |type| + Option::KW.(proc) do |type| options[:name] ||= proc if type == :symbol options[:name] ||= "#{kws[:definer_name]}:#{proc.source_location.last}" if proc.is_a? Proc if type == :proc options[:name] ||= proc.class if type == :callable end end