Class: Approvals::Writers::BinaryWriter
- Inherits:
-
Object
- Object
- Approvals::Writers::BinaryWriter
- 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
-
#format ⇒ Object
Returns the value of attribute format.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ BinaryWriter
constructor
A new instance of BinaryWriter.
- #register ⇒ Object
- #unregister ⇒ Object
- #write(data, path) ⇒ Object
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
#format ⇒ Object
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
#register ⇒ Object
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 |
#unregister ⇒ Object
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 |