Class: BundleUpdateInteractive::CLI::Table
- Inherits:
-
Object
- Object
- BundleUpdateInteractive::CLI::Table
- Defined in:
- lib/bundle_update_interactive/cli/table.rb
Class Method Summary collapse
Instance Method Summary collapse
- #gem_names ⇒ Object
-
#initialize(gems, columns) ⇒ Table
constructor
A new instance of Table.
- #render ⇒ Object
- #render_gem(name) ⇒ Object
- #render_header ⇒ Object
Constructor Details
#initialize(gems, columns) ⇒ Table
Returns a new instance of Table.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 33 def initialize(gems, columns) @pastel = BundleUpdateInteractive.pastel @headers = columns.map { |header, _| pastel.dim.underline(header) } @rows = gems.transform_values do |gem| row = Row.new(gem) columns.map do |_, col| case col when Symbol then row.public_send(col).to_s when String then col end end end @column_widths = calculate_column_widths end |
Class Method Details
.updatable(gems) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 20 def updatable(gems) columns = [ ["name", :formatted_gem_name], ["from", :formatted_current_version], [nil, "→"], ["to", :formatted_updated_version], ["group", :formatted_gemfile_groups], ["url", :formatted_changelog_uri] ] new(gems, columns) end |
.withheld(gems) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 8 def withheld(gems) columns = [ ["name", :formatted_gem_name], ["requirement", :formatted_gemfile_requirement], ["current", :formatted_current_version], ["latest", :formatted_updated_version], ["group", :formatted_gemfile_groups], ["url", :formatted_changelog_uri] ] new(gems, columns) end |
Instance Method Details
#gem_names ⇒ Object
48 49 50 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 48 def gem_names rows.keys end |
#render ⇒ Object
61 62 63 64 65 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 61 def render lines = [render_header] rows.keys.sort.each { |name| lines << render_gem(name) } lines.join("\n") end |
#render_gem(name) ⇒ Object
56 57 58 59 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 56 def render_gem(name) row = rows.fetch(name) render_row(row) end |
#render_header ⇒ Object
52 53 54 |
# File 'lib/bundle_update_interactive/cli/table.rb', line 52 def render_header render_row(headers) end |