Sha256: 7372b11b62a29e3e8030776edae65ed39f63bbd4b89a95ac21de4cc16f3db078

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

module Approvals
  module Writers
    class BinaryWriter
      EXCEPTION_WRITER = Proc.new do |data, file|
        raise "BinaryWriter#callback missing"
      end

      def initialize(opts = {})
        self.autoregister = opts[:autoregister] || true
        self.detect = opts[:detect]
        self.extension = opts[:extension] || ''
        self.write = opts[:write] || EXCEPTION_WRITER
        self.format = opts[:format] || :binary
      end

      attr_accessor :autoregister
      attr_accessor :extension
      attr_accessor :write
      attr_accessor :detect


      attr_reader :format

      def format=(sym)
        unregister if autoregister

        @format = sym

        register if autoregister

      end

      def register
        if @format
          Writer::REGISTRY[@format] = self
          Approval::BINARY_FORMATS << @format
          Approval::IDENTITIES[@format] = @detect if @detect
        end
      end

      def unregister
        if @format
          Writer::REGISTRY.delete!(@format)
          Approval::BINARY_FORMATS.delete!(@format)
          Approval::IDENTITIES.delete!(@format)
        end
      end

      def write(data,path)
        @write.call(data,path)
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
approvals-0.0.20 lib/approvals/writers/binary_writer.rb
approvals-0.0.19 lib/approvals/writers/binary_writer.rb
approvals-0.0.18 lib/approvals/writers/binary_writer.rb
approvals-0.0.17 lib/approvals/writers/binary_writer.rb
approvals-0.0.16 lib/approvals/writers/binary_writer.rb
approvals-0.0.15 lib/approvals/writers/binary_writer.rb
approvals-0.0.14 lib/approvals/writers/binary_writer.rb
approvals-0.0.13 lib/approvals/writers/binary_writer.rb