Sha256: 35c37871ce4f8852832c4f8215f39ec92827b1115f86657032281dd4a491ac1b

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

module Hover
  module Encoder
    class JSONStream
      attr_accessor :file

      def initialize
      end

      def open(path)
        self.file = File.open(path, 'w')
      end

      def close
        self.file.close
        self.file = nil
      end

      def append(attributes, klass)
        self.file.puts(JSON.dump(attributes.merge('class' => klass.name)))
      end

      def append_each(attributes_sets, klass)
        attributes_sets.each do |attributes|
          append(attributes, klass)
        end
      end

      def append_records(scope)
        scope.find_each do |record|
          append(record.attributes.as_json, record.class)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hover-ruby-client-0.4.0 lib/hover/encoder/json_stream.rb
hover-ruby-client-0.3.1 lib/hover/encoder/json_stream.rb