Class: Gemsmith::Rake::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/gemsmith/rake/publisher.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_spec: Gemsmith::Gem::Specification.new(self.class.gem_spec_path), gem_config: Gemsmith::CLI.configuration.to_h, credentials: Gemsmith::Credentials, publisher: Milestoner::Publisher.new, shell: Bundler::UI::Shell.new, kernel: Kernel) ⇒ Publisher

rubocop:disable Metrics/ParameterLists



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gemsmith/rake/publisher.rb', line 18

def initialize gem_spec: Gemsmith::Gem::Specification.new(self.class.gem_spec_path),
               gem_config: Gemsmith::CLI.configuration.to_h,
               credentials: Gemsmith::Credentials,
               publisher: Milestoner::Publisher.new,
               shell: Bundler::UI::Shell.new,
               kernel: Kernel

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

Class Method Details

.gem_spec_pathObject



13
14
15
# File 'lib/gemsmith/rake/publisher.rb', line 13

def self.gem_spec_path
  String Dir["#{Dir.pwd}/*.gemspec"].first
end

Instance Method Details

#publishObject



43
44
45
46
47
48
# File 'lib/gemsmith/rake/publisher.rb', line 43

def publish
  publisher.publish gem_spec.version_number, sign: signed?
  push
rescue Milestoner::Errors::Base => error
  shell.error error.message
end

#pushObject



33
34
35
36
37
38
39
40
41
# File 'lib/gemsmith/rake/publisher.rb', line 33

def push
  creds = credentials.new key: gem_spec.allowed_push_key.to_sym,
                          url: gem_spec.allowed_push_host
  creds.create

  options = %(--key "#{translate_key creds.key}" --host "#{gem_spec.allowed_push_host}")
  status = kernel.system %(gem push "pkg/#{gem_spec.package_file_name}" #{options})
  process_push status
end

#signed?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/gemsmith/rake/publisher.rb', line 50

def signed?
  gem_config.dig :publish, :sign
end