Sha256: 484e801c11a5da101881fe36ecd0d073f3ab11ba447b83d829b1f1eb19f9ab0b

Contents?: true

Size: 803 Bytes

Versions: 5

Compression:

Stored size: 803 Bytes

Contents

module Alf
  class Reader
    #
    # Specialization of the Reader contract for .rash files.
    #
    # A .rash file/stream contains one ruby hash literal on each line. This 
    # reader simply decodes each of them in turn with Kernel.eval, providing a 
    # state-less reader (that is, tuples are not all loaded in memory at once).
    #
    class Rash < Reader

      # (see Reader#line2tuple)
      def line2tuple(line)
        begin
          h = Kernel.eval(line)
          raise "hash expected, got #{h}" unless h.is_a?(Hash)
        rescue Exception => ex
          $stderr << "Skipping #{line.strip}: #{ex.message}\n"
          nil
        else
          return h
        end
      end

      Reader.register(:rash, [".rash"], self)
    end # class Rash
  end # class Reader
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf/reader/rash.rb
alf-0.12.1 lib/alf/reader/rash.rb
alf-0.12.0 lib/alf/reader/rash.rb
alf-0.11.1 lib/alf/reader/rash.rb
alf-0.11.0 lib/alf/reader/rash.rb