Sha256: 9938963eec576dfb6bec18cea69db8df61908c5086e2152b64f465f31752a915

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

module AssOle
  module Snippets
    module Shared
      # Snippet for puck/unpack
      # data to/from 1C BinaryData
      module BinaryData
        require 'tempfile'
        is_ole_snippet

        # @api private
        class TempFile
          include AssOle::Snippets::IsSnippet::WinPath

          attr_reader :data
          def initialize(data)
            @data = data
          end

          def win_path
            real_win_path path
          end

          def write
            temp_file.write(data)
            temp_file.close
          end

          def read
            temp_file.open
            temp_file.read
          end

          def temp_file
            @temp_file ||= Tempfile.new('ass_ole_bin_data')
          end

          def exist?
            return false unless path
            File.exist? path
          end

          def rm!
            temp_file.unlink if exist?
          end

          def path
            temp_file.path
          end
        end

        # Packing data to 1C BinaryData
        # @param data data for packing
        # @return [WIN32OLE]
        def binary_data(data)
          temp_file = TempFile.new(data)
          temp_file.write
          result = newObject('BinaryData', temp_file.win_path)
          result
        ensure
          temp_file.rm!
        end

        # Unpacking data form 1C BinaryData
        # @param ole_bin_data [WIN32OLE] 1C BinaryData
        def binary_data_get(ole_bin_data)
          temp_file = TempFile.new(nil)
          temp_file.temp_file.close
          ole_bin_data.Write(temp_file.win_path)
          temp_file.read
        ensure
          temp_file.rm!
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ass_ole-snippets-shared-0.5.0 lib/ass_ole/snippets/shared/binary_data.rb
ass_ole-snippets-shared-0.4.0 lib/ass_ole/snippets/shared/binary_data.rb
ass_ole-snippets-shared-0.3.2 lib/ass_ole/snippets/shared/binary_data.rb
ass_ole-snippets-shared-0.3.1 lib/ass_ole/snippets/shared/binary_data.rb
ass_ole-snippets-shared-0.3.0 lib/ass_ole/snippets/shared/binary_data.rb
ass_ole-snippets-shared-0.2.0 lib/ass_ole/snippets/shared/binary_data.rb