Sha256: 15467c882f2a0d9d6866eefb46eba5e5e294a722b0c58097347698cef9f0501a

Contents?: true

Size: 1.04 KB

Versions: 104

Compression:

Stored size: 1.04 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
          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

104 entries across 104 versions & 2 rubygems

Version Path
avm-eac_ruby_base1-0.29.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.55.2 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.55.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.55.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.29.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.54.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.53.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.28.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.52.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.28.0 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.51.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.50.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.49.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.48.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.48.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.27.3 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.47.2 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.27.2 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.47.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.47.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb