Sha256: a3d8f10c51059efd354a270d8388d36e86c55fc2638d550a8938899593ffa032

Contents?: true

Size: 1.7 KB

Versions: 14

Compression:

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

        RUBOCOP_OK_CODES = [256].freeze

        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)
            .execute!(exit_outputs: RUBOCOP_OK_CODES.index_with { |_k| nil })
        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

14 entries across 14 versions & 2 rubygems

Version Path
avm-eac_ruby_base1-0.35.1 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.96.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
avm-eac_ruby_base1-0.35.0 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.95.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
avm-eac_ruby_base1-0.34.1 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.91.1 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
avm-eac_ruby_base1-0.34.0 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.91.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
avm-eac_ruby_base1-0.33.1 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.83.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.82.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.81.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
avm-eac_ruby_base1-0.33.0 lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb
eac_tools-0.80.0 sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/update_dependency_requirements.rb