Class: GemKit::Release::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_kit/release/commands/command.rb

Overview

Shared base for the commands behind gem kit. Each is thin — ask a library object a question, report — and knows nothing about Thor. The work stays in Gate, VersionFile, Changelog and Deprecate; the parsing, the help pages and the generator machinery stay in Thor.

Direct Known Subclasses

Bump, Changelog, Deprecations, Release, Tag

Constant Summary collapse

RED =
"\e[0;31m"
RESET =
"\e[0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Command

Returns a new instance of Command.



22
23
24
# File 'lib/gem_kit/release/commands/command.rb', line 22

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/gem_kit/release/commands/command.rb', line 20

def options
  @options
end

Instance Method Details

#fail_with(message) ⇒ Object

Raises:



45
46
47
# File 'lib/gem_kit/release/commands/command.rb', line 45

def fail_with(message)
  raise Failure, message
end

#gateObject



35
36
37
# File 'lib/gem_kit/release/commands/command.rb', line 35

def gate
  @gate ||= Gate.new(project)
end

#lines(entries) ⇒ Object

Deprecation entries as display lines: the deadline, the rename, and where it was declared.



63
64
65
66
67
68
# File 'lib/gem_kit/release/commands/command.rb', line 63

def lines(entries)
  entries.sort_by { |entry| [entry.removed_in, entry.name] }.flat_map do |entry|
    line = "#{entry.removed_in.to_s.ljust(8)} #{entry}"
    entry.declared_at ? [line, "#{" " * 8} #{entry.declared_at}"] : [line]
  end
end

#projectObject

The gem in the working directory. Everything is inferred from its .gemspec, so there is nothing to configure in the common case. --gem picks one out of a repository holding several.



29
30
31
32
33
# File 'lib/gem_kit/release/commands/command.rb', line 29

def project
  @project ||= Project.detect(Dir.pwd, name: options[:gem])
rescue Project::NotFound, Project::Ambiguous => error
  fail_with(error.message)
end

#refuse(heading, problems) ⇒ Object

Report a problem list under a heading and stop. One message — a refusal is not half output and half diagnostics.



51
52
53
# File 'lib/gem_kit/release/commands/command.rb', line 51

def refuse(heading, problems)
  fail_with([heading, "", *problems.map { |problem| "  #{problem}" }].join("\n"))
end

#relative(path) ⇒ Object



55
# File 'lib/gem_kit/release/commands/command.rb', line 55

def relative(path) = path.sub("#{project.root}/", "")

#render(entries) ⇒ Object



57
58
59
# File 'lib/gem_kit/release/commands/command.rb', line 57

def render(entries)
  lines(entries).each { |line| say("  #{line}") }
end

#say(message = "") ⇒ Object



43
# File 'lib/gem_kit/release/commands/command.rb', line 43

def say(message = "") = $stdout.puts(message)

#version_fileObject



39
40
41
# File 'lib/gem_kit/release/commands/command.rb', line 39

def version_file
  VersionFile.new(project.version_file, template: project.version_template)
end