lib/lou/transformer.rb in lou-0.1.0 vs lib/lou/transformer.rb in lou-0.2.0

- old
+ new

@@ -1,21 +1,33 @@ +require 'active_support/core_ext/class/attribute' +require 'lou/transformer/step' + module Lou - class Transformer - def up(&block) - @up = block - self + module Transformer + def self.extended(base) + base.class_eval do + class_attribute(:steps) + self.steps = [] + end end - def down(&block) - @down = block - self + def step + Step.new.tap do |t| + steps << t + end end def apply(input) - @up.nil? ? input : @up.call(input) + steps.each do |t| + input = t.apply(input) + end + input end def reverse(output) - @down.nil? ? output : @down.call(output) + steps.reverse_each do |t| + output = t.reverse(output) + end + output end end end