Sha256: 686540900d671142a5140d833190854e11272dd64474bdb59927d93bba004e7d

Contents?: true

Size: 1.01 KB

Versions: 18

Compression:

Stored size: 1.01 KB

Contents

module Rake
  module Funnel
    module Support
      class BinaryVersionReader
        class << self
          KNOWN_ATTRIBUTES = [:company_name, :file_description, :file_version, :legal_copyright, :product_name, :product_version, :assembly_version]
          SEPARATOR = "\0"
          TERMINATOR = "\0" * 3

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

            attributes = KNOWN_ATTRIBUTES.map { |attr|
              read_attribute(binary, attr)
            }

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

            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}" => data[1].gsub(/#{SEPARATOR}/, '') }
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rake-funnel-0.18.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.17.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.16.1 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.16.0 lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.15.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.14.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.13.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.12.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.11.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.10.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.9.1.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.9.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.8.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.7.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.6.1.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.6.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.5.0.pre lib/rake/funnel/support/binary_version_reader.rb
rake-funnel-0.4.0.pre lib/rake/funnel/support/binary_version_reader.rb