Sha256: 5c8a0d576869fd10d355fdd49037d50d81c20dc5546e22d707c18bf1c59a6293

Contents?: true

Size: 1.34 KB

Versions: 109

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/object'

module Avm
  module Launcher
    module Ruby
      module Gem
        class Specification
          class << self
            def parse_version_file(file)
              s = ::File.read(file)
              m = /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.match(s)
              m ? m[1] : nil
            end
          end

          attr_reader :gemspec_file

          def initialize(gemspec_file)
            @gemspec_file = gemspec_file
          end

          def version
            v = self.class.parse_version_file(version_file)
            return v if v.present?

            raise "Version not found on file \"#{version_file}\""
          end

          def name
            ::File.basename(gemspec_file).gsub(/\.gemspec\z/, '')
          end

          def full_name
            "#{name}-#{version}"
          end

          def to_s
            full_name
          end

          private

          def gem_root
            ::File.dirname(gemspec_file)
          end

          def version_file
            f = ::File.join(gem_root, 'lib', *namespace_parts, 'version.rb')
            return f if ::File.exist?(f)

            raise "Version file \"#{f}\" does not exist"
          end

          def namespace_parts
            name.split('-')
          end
        end
      end
    end
  end
end

Version data entries

109 entries across 109 versions & 2 rubygems

Version Path
eac_tools-0.16.1 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.129.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.16.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.128.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.15.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.14.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.13.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.127.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.12.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.126.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.11.1 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.125.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.11.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.124.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.10.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.123.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.9.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
avm-tools-0.122.0 lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.8.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb
eac_tools-0.7.0 sub/avm-tools/lib/avm/launcher/ruby/gem/specification.rb