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.30.3 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.65.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.65.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.64.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.63.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.62.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.62.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.61.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.61.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.30.2 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.60.3 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.60.2 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.60.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.60.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.59.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
avm-eac_ruby_base1-0.30.1 lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.58.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.57.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.56.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb
eac_tools-0.56.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/rubygems/version_file.rb