Sha256: 792e752f0c9a94385d89e03cf3dfa66694985866e285e551af35069095f2597c

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require 'avm/eac_ruby_base1/preferred_version_requirements'
require 'eac_ruby_utils/core_ext'

module Avm
  module EacRubyBase1
    module Sources
      class UpdateDependencyRequirements
        enable_simple_cache
        common_constructor :source, :gem_name

        def perform
          source.scm.commit_if_change(commit_message) { update_code }
        end

        private

        # @return [String]
        def commit_message
          i18n_translate(__method__,
                         name: gem_name,
                         requirements_list: requirements_list.join(', '),
                         __locale: source.locale)
        end

        def format_gemspec
          source.rubocop_command.ignore_parent_exclusion(true).autocorrect(true)
            .file(source.gemspec_path).system!
        end

        # @return [Array<String>]
        def requirements_list_uncached
          ::Avm::EacRubyBase1::PreferredVersionRequirements.new(
            source.gemfile_lock_gem_version(gem_name)
          ).to_requirements_list
        end

        def gemspec_uncached
          ::Avm::EacRubyBase1::Rubygems::Gemspec.from_file(source.gemspec_path)
        end

        def parent_bundle
          source.parent.if_present(&:on_sub_updated)
        end

        def update_code
          update_gemspec
          source.bundle.system!
          parent_bundle
        end

        def update_gemspec
          gemspec.dependency(gem_name).version_specs = requirements_list
          gemspec.write(source.gemspec_path)
          format_gemspec
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
avm-eac_ruby_base1-0.32.0 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.77.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb