Sha256: 1845f6b073a9dcbaf2bdb8b30e4b7bbc93d7522a4ae8d4326b9ba5e8b65e6a19

Contents?: true

Size: 680 Bytes

Versions: 3

Compression:

Stored size: 680 Bytes

Contents

module Sexpr
  class Processor
    class Helper

      attr_accessor :next_in_chain

      def call(processor, sexpr, &bl)
        meth = :"on_#{sexpr.first}"
        meth = :"on_missing" unless respond_to?(meth)
        send(meth, processor, sexpr) do |r,n|
          next_call(r, n, bl)
        end
      end

      def on_missing(processor, sexpr)
        yield(processor, sexpr)
      end

      private

      def next_call(processor, sexpr, toplevel)
        if nic = next_in_chain
          nic.call(processor, sexpr, &toplevel)
        else
          toplevel.call(processor, sexpr)
        end
      end

    end # class Helper
  end # module Processor
end # module Sexpr

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sexpr-0.5.1 lib/sexpr/processor/helper.rb
sexpr-0.5.0 lib/sexpr/processor/helper.rb
sexpr-0.4.0 lib/sexpr/processor/helper.rb