class Gemsmith::Rake::Publisher

Provides gem release functionality. Meant to be wrapped in Rake tasks. :reek: TooManyInstanceVariables

Attributes

credentials[R]
gem_config[R]
gem_spec[R]
kernel[R]
milestoner_container[R]
publisher[R]
shell[R]

Public Class Methods

gem_spec_path() click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 18
def self.gem_spec_path
  Pathname.pwd.files("*.gemspec").first.to_s
end
new(gem_spec: Gemsmith::Gem::Specification.new(self.class.gem_spec_path.to_s), gem_config: Gemsmith::CLI.configuration.to_h, credentials: Gemsmith::Credentials, publisher: Milestoner::Tags::Publisher.new, milestoner_container: Milestoner::Container, shell: Bundler::UI::Shell.new, kernel: Kernel) click to toggle source

rubocop:disable Metrics/ParameterLists :reek: LongParameterList

# File lib/gemsmith/rake/publisher.rb, line 24
def initialize gem_spec: Gemsmith::Gem::Specification.new(self.class.gem_spec_path.to_s),
               gem_config: Gemsmith::CLI.configuration.to_h,
               credentials: Gemsmith::Credentials,
               publisher: Milestoner::Tags::Publisher.new,
               milestoner_container: Milestoner::Container,
               shell: Bundler::UI::Shell.new,
               kernel: Kernel

  @gem_spec = gem_spec
  @gem_config = gem_config
  @credentials = credentials
  @publisher = publisher
  @milestoner_container = milestoner_container
  @shell = shell
  @kernel = kernel
end

Public Instance Methods

publish() click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 50
def publish
  milestoner_configuration.merge(git_tag_version: gem_spec.version, git_tag_sign: signed?)
                          .then { |configuration| publisher.call configuration }
  push
rescue Milestoner::Error => error
  shell.error error.message
end
push() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/gemsmith/rake/publisher.rb, line 42
def push
  credentials.new(key: gem_spec.allowed_push_key.to_sym, url: gem_host)
             .tap(&:create)
             .then { |creds| %(--key "#{translate_key creds.key}" --host "#{gem_host}") }
             .then { |options| execute_push options }
             .then { |status| output_push status }
end
signed?() click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 58
def signed?
  gem_config.dig :publish, :sign
end

Private Instance Methods

execute_push(options) click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 80
def execute_push options
  kernel.system %(gem push "pkg/#{gem_spec.package_file_name}" #{options})
end
gem_host() click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 72
def gem_host
  gem_spec.allowed_push_host
end
milestoner_configuration(= milestoner_container[:configuration]) click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 97
  def milestoner_configuration = milestoner_container[:configuration]
end
output_push(status) click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 84
def output_push status
  package = gem_spec.package_file_name

  if status
    shell.confirm "Pushed #{package} to #{gem_host}."
  else
    shell.error "Failed pushing #{package} to #{gem_host}. " \
                "Check gemspec and gem credential settings."
  end

  status
end
translate_key(key) click to toggle source
# File lib/gemsmith/rake/publisher.rb, line 76
def translate_key key
  key == credentials::DEFAULT_KEY ? :rubygems : key
end