Class: Approvals::Writers::BinaryWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/approvals/writers/binary_writer.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BinaryWriter

Returns a new instance of BinaryWriter.



8
9
10
11
12
13
14
# File 'lib/approvals/writers/binary_writer.rb', line 8

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

Instance Attribute Details

#formatObject

Returns the value of attribute format.



16
17
18
# File 'lib/approvals/writers/binary_writer.rb', line 16

def format
  @format
end

Instance Method Details

#registerObject



27
28
29
30
31
32
33
# File 'lib/approvals/writers/binary_writer.rb', line 27

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

#unregisterObject



35
36
37
38
39
40
41
# File 'lib/approvals/writers/binary_writer.rb', line 35

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

#write(data, path) ⇒ Object



43
44
45
# File 'lib/approvals/writers/binary_writer.rb', line 43

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