Sha256: 227481f7feb096453c9f4ecb56569204f8811af78a02b50507f7ec4c9c40025c

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

module Rake
  module Funnel
    module Support
      class BinaryVersionReader
        class << self
          KNOWN_ATTRIBUTES = %i(company_name
                                file_description
                                file_version
                                legal_copyright
                                product_name
                                product_version
                                assembly_version).freeze
          SEPARATOR = "\0".freeze
          TERMINATOR = "\0" * 3

          def read_from(assembly)
            binary = File.binread(assembly)

            attributes = KNOWN_ATTRIBUTES.map do |attr|
              read_attribute(binary, attr)
            end

            hash = attributes.inject({}) do |memo, attr|
              memo.merge(attr)
            end

            VersionInfo.new(hash)
          end

          private

          def read_attribute(binary, attr)
            binary_attr = attr.pascalize.gsub(/(.)/) { |match| match + SEPARATOR }

            data = binary.match(/#{binary_attr}#{SEPARATOR}+(.*?)#{TERMINATOR}/)
            return {} if data.nil?

            { attr.to_s => data[1].gsub(/#{SEPARATOR}/, '') }
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake-funnel-0.22.2 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.22.1 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.22.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.21.2 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.21.1 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.21.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.20.2 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.20.1 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.20.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.19.0 lib/rake/funnel/support/binary_version_reader.rb