module EacLauncher module Stereotypes class RubyGem class Publish < ::EacLauncher::Publish::Base include ::Eac::SimpleCache include ::EacRubyUtils::Console::Speaker def initialize(instance) @instance = instance end protected def internal_check if new_and_unpublishing_new? ::EacLauncher::Publish::CheckResult.blocked( "#{gem_spec.full_name} does not exist in RubyGems" ) elsif version_already_pushed? ::EacLauncher::Publish::CheckResult.updated("#{gem_spec.full_name} already pushed") else ::EacLauncher::Publish::CheckResult.pending("#{gem_spec.full_name} not found " \ 'in RubyGems') end end private def source_uncached @instance.current_cache end def gem_spec_uncached ::EacLauncher::Stereotypes::RubyGem.load_gemspec(gemspec) end def gem_build_uncached ::EacLauncher::Ruby::Gem::Build.new(source) end def publish gem_build.open push_gem ensure gem_build.close end def new_and_unpublishing_new? !gem_exist_in_rubygems? && !::EacLauncher::Context.current.publish_options[:new] end def gem_exist_in_rubygems? gem_versions.any? end def version_already_pushed? gem_versions.any? { |v| v['number'] == gem_spec.version } end def gem_versions_uncached http = Curl.get("https://rubygems.org/api/v1/versions/#{gem_spec.name}.json") return JSON.parse!(http.body_str) if /\A2/ =~ http.status return [] if /\A4/ =~ http.status raise "#{http} code error: #{http.status}" end def push_gem info("Pushing gem #{gem_spec}...") if ::EacLauncher::Context.current.publish_options[:confirm] EacRubyUtils::Envs.local.command('gem', 'push', gem).system info('Pushed!') else warn('Not pushed because not confirmed') end end def gemspec_uncached source.find_file_with_extension('.gemspec') end end end end end