module Eco module API class UseCases # InputOutput class for usecases. # @note Same as Eco::API::UseCases::BaseIO but: # - includes `type` of usecase # - provides a helper to `chain` InputOutput between usecases # @attr_reader usecase [Eco::API::UseCases::UseCase] the usecase this InputOuput is linked to class UseCaseIO < BaseIO @types = BaseIO.types attr_reader :usecase # @see Eco::API::UseCases::BaseIO#initialize def initialize(usecase:, **kargs) self.usecase = usecase super(**kargs) end # @see Eco::API::UseCases::BaseIO#new # @param usecase [Eco::API::UseCases::UseCase] target usecase # @return [Eco::API::UseCases::UseCaseIO] def new(usecase:, **kargs) super(**kargs.merge(usecase: usecase)) end # @param value [Eco::API::UseCases::UseCase] the usecase this InputOuput should be linked to def usecase=(value) raise "It should be a Eco::API::UseCases::UseCase. Given: #{value}" if !value.is_a?(Eco::API::UseCases::UseCase) @usecase = value end # @return [Symbol] the `type` of the UseCase this InputOuput is linked to def type @usecase.type end def type=(value) raise "Can't modify type depends on the usecase linked to this IO object" end # @see Eco::API::UseCases::BaseIO#params # Same as its superclass but adding `usecase` parameter def params(keyed: false) super(keyed: keyed).tap do |res| if keyed res.merge!(usecase: usecase) else res.push(usecase) end end end def chain(usecase:) raise "It should be a UseCase. Given: #{usecase}" if !usecase.is_a?(UseCase) aux_io = self.class.new(input: input, people: people, session: session, options: options, usecase: usecase) kargs = aux_io.params(keyed: true) case self.type when :import kargs[:input] = output when :filter kargs[:people] = output when :transform, :sync, :export # no redirections => should it redirect the input? end self.class.new(kargs) end end end end end