Sha256: b7faf439a1b3fcc4b0d1a0b7a6a9876cee7cbc83dba04b631ee28cea043f127c

Contents?: true

Size: 1.07 KB

Versions: 67

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module EacRubyBase1
    module Rubygems
      class VersionFile
        common_constructor :path

        VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze

        def value
          return nil unless path.file?

          path.read.each_line.lazy.map { |line| line_value(line) }.find { |v| v }
        end

        def value=(new_value)
          path.write(new_value_content(new_value))
        end

        private

        # @return Version found in line, nil otherwise.
        def line_value(line)
          VERSION_LINE_PATTERN.if_match(line.rstrip, false) { |m| ::Gem::Version.new(m[2]) }
        end

        def new_value_content(new_value)
          path.read.each_line
            .map { |line| new_value_line(line, new_value) }
            .join
        end

        def new_value_line(line, new_value)
          m = VERSION_LINE_PATTERN.match(line)
          return line unless m

          "#{m[1]}VERSION = '#{new_value}'#{m[3]}"
        end
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 2 rubygems

Version Path
avm-eac_ruby_base1-0.35.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.96.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.35.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.95.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.34.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.91.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.34.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.91.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.33.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.83.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.82.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.81.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.33.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.80.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.79.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.32.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.78.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.32.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.77.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.77.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb