class WhatTheGem::Command
Constants
- HEADER_TEMPLATE
FIXME: It was > **{{ info.info | paragraphs:1 }}** but it looks weird due to tty-markdown bug: github.com/piotrmurach/tty-markdown/issues/11
- Meta
Attributes
meta[R]
gem[R]
Public Class Methods
call(*args)
click to toggle source
# File lib/whatthegem/commands.rb, line 27 def call(*args) new(*args).call end
get(handle)
click to toggle source
# File lib/whatthegem/commands.rb, line 23 def get(handle) Command.registry[handle] end
new(gem)
click to toggle source
# File lib/whatthegem/commands.rb, line 50 def initialize(gem) @gem = gem end
register(title: name.split('::').last, handle: title.downcase, description:)
click to toggle source
# File lib/whatthegem/commands.rb, line 14 def register(title: name.split('::').last, handle: title.downcase, description:) Command.registry[handle] = self @meta = Meta.new( handle: handle, title: title, description: description ) end
registry()
click to toggle source
# File lib/whatthegem/commands.rb, line 8 def registry {} end
Public Instance Methods
call()
click to toggle source
# File lib/whatthegem/commands.rb, line 58 def call puts full_output end
meta()
click to toggle source
# File lib/whatthegem/commands.rb, line 54 def meta self.class.meta end
Private Instance Methods
full_output()
click to toggle source
# File lib/whatthegem/commands.rb, line 64 def full_output gm = gem # otherwise next line breaks Sublime highlighting... return %{Gem "#{gm.name}" is not registered at rubygems.org.} unless gem.exists? header_locals.then(&HEADER_TEMPLATE).then(&method(:markdown)) + output end
guess_uris(info)
click to toggle source
# File lib/whatthegem/commands.rb, line 90 def guess_uris(info) [ info[:source_code_uri], info.values_at(:homepage_uri, :documentation_uri, :project_uri).compact.reject(&:empty?).first ] .compact.reject(&:empty?).uniq { |u| u.chomp('/').sub('http:', 'https:') } end
header_locals()
click to toggle source
# File lib/whatthegem/commands.rb, line 74 def header_locals { title: meta.title, info: gem.rubygems.info, uris: guess_uris(gem.rubygems.info), } end
markdown(text)
click to toggle source
# File lib/whatthegem/commands.rb, line 82 def markdown(text) TTY::Markdown.parse(text) end
output()
click to toggle source
# File lib/whatthegem/commands.rb, line 70 def output locals.then(&template) end
template()
click to toggle source
# File lib/whatthegem/commands.rb, line 86 def template self.class::TEMPLATE end