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 = {})
  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

Instance Attribute Details

#autoregisterObject

Returns the value of attribute autoregister.



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

def autoregister
  @autoregister
end

#detectObject

Returns the value of attribute detect.



19
20
21
# File 'lib/approvals/writers/binary_writer.rb', line 19

def detect
  @detect
end

#extensionObject

Returns the value of attribute extension.



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

def extension
  @extension
end

#formatObject

Returns the value of attribute format.



22
23
24
# File 'lib/approvals/writers/binary_writer.rb', line 22

def format
  @format
end

#write(data, path) ⇒ Object

Returns the value of attribute write.



18
19
20
# File 'lib/approvals/writers/binary_writer.rb', line 18

def write
  @write
end

Instance Method Details

#registerObject



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

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

#unregisterObject



41
42
43
44
45
46
47
# File 'lib/approvals/writers/binary_writer.rb', line 41

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