class Librarian::Cli::ManifestPresenter

Attributes

cli[RW]
manifests[RW]
manifests_index[RW]
scope_level[RW]

Public Class Methods

new(cli, manifests) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 8
def initialize(cli, manifests)
  self.cli = cli or raise ArgumentError, "cli required"
  self.manifests = manifests or raise ArgumentError, "manifests required"
  self.manifests_index = Hash[manifests.map{|m| [m.name, m]}]

  self.scope_level = 0
end

Public Instance Methods

present(names = [], options = { }) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 16
def present(names = [], options = { })
  full = options[:detailed]
  full = !names.empty? if full.nil?

  names = manifests.map(&:name).sort if names.empty?
  assert_no_manifests_missing!(names)

  present_each(names, :detailed => full)
end
present_one(manifest, options = { }) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 26
def present_one(manifest, options = { })
  full = options[:detailed]

  say "#{manifest.name} (#{manifest.version})" do
    full or next

    present_one_source(manifest)
    present_one_dependencies(manifest)
  end
end

Private Instance Methods

assert_no_manifests_missing!(names) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 80
def assert_no_manifests_missing!(names)
  missing_names = names.reject{|name| manifest(name)}
  unless missing_names.empty?
    raise Error, "not found: #{missing_names.map(&:inspect).join(', ')}"
  end
end
manifest(name) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 63
def manifest(name)
  manifests_index[name]
end
present_each(names, options) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 39
def present_each(names, options)
  names.each do |name|
    manifest = manifest(name)
    present_one(manifest, options)
  end
end
present_one_dependencies(manifest) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 50
def present_one_dependencies(manifest)
  manifest.dependencies.empty? and return

  say "dependencies:" do
    deps = manifest.dependencies.sort_by(&:name)
    deps.each do |dependency|
      say "#{dependency.name} (#{dependency.requirement})"
    end
  end
end
present_one_source(manifest) click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 46
def present_one_source(manifest)
  say "source: #{manifest.source}"
end
say(string) { || ... } click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 67
def say(string)
  cli.say "  " * scope_level << string
  scope { yield } if block_given?
end
scope() { || ... } click to toggle source
# File lib/librarian/cli/manifest_presenter.rb, line 72
def scope
  original_scope_level = scope_level
  self.scope_level = scope_level + 1
  yield
ensure
  self.scope_level = original_scope_level
end