Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created July 15, 2015 18:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/c62bb892087957a315f5 to your computer and use it in GitHub Desktop.
Save scottmessinger/c62bb892087957a315f5 to your computer and use it in GitHub Desktop.
Importer with Transproc
preprocessor = Preprocessor.build
processor = Processor.build
evaluator = InputFunctions[:eval_values, [{ 'jd' => 'jd001' }]]
create_authors_with_books = rom.command([
:authors, [:create, [:books, [:create]]]
])
module Flow
extend Transproc::Registry
def self.preprocess(input)
preprocessor.call(input)
end
def self.validate(input)
if input.all? { |author| Validator.new(author).valid? }
input
end
end
def self.process(input)
processor.call(input).map { |author| evaluator.call(author) } if input
end
def self.persist(input)
create_authors_with_books.call(authors: input) if input
end
end
result = Flow(:preprocess) >> Flow(:validate) >> Flow(:process) >> Flow(:persist)
result.call(raw_input)
@solnic
Copy link

solnic commented Sep 22, 2015

We have :guard in transproc that goes like this:

irb(main):004:0> require 'transproc/all'
=> true
irb(main):005:0> include Transproc::Registry
irb(main):006:0> import Transproc::Conditional
=> main
irb(main):007:0> t(:guard, -> input { input > 1 }, -> input { puts 'MORE THAN 1!' })[2]
MORE THAN 1!
=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment