Class: Glimmer::RakeTask::List

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/rake_task/list.rb

Overview

Lists Glimmer related gems to use in rake_task.rb

Constant Summary collapse

REGEX_GEM_LINE =
/^([^\(]+) \(([^\)]+)\)$/

Class Method Summary collapse

Class Method Details

.custom_control_gems(query = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/glimmer/rake_task/list.rb', line 32

def custom_control_gems(query=nil)
  list_gems('glimmer-libui-cc-', query) do |result|
    puts
    puts "  Glimmer DSL for LibUI Custom Control Gems#{" matching [#{query}]" if query} at rubygems.org:"
    puts result
  end
end

.custom_shape_gems(query = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/glimmer/rake_task/list.rb', line 48

def custom_shape_gems(query=nil)
  list_gems('glimmer-libui-cs-', query) do |result|
    puts
    puts "  Glimmer DSL for LibUI Custom Shape Gems#{" matching [#{query}]" if query} at rubygems.org:"
    puts result
  end
end

.custom_window_gems(query = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/glimmer/rake_task/list.rb', line 40

def custom_window_gems(query=nil)
  list_gems('glimmer-libui-cw-', query) do |result|
    puts
    puts "  Glimmer DSL for LibUI Custom Window Gems#{" matching [#{query}]" if query} at rubygems.org:"
    puts result
  end
end

.dsl_gems(query = nil) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/glimmer/rake_task/list.rb', line 56

def dsl_gems(query=nil)
  list_gems('glimmer-dsl-', query) do |result|
    puts
    puts "  Glimmer DSL Gems#{" matching [#{query}]" if query} at rubygems.org:"
    puts result
  end
end

.list_gems(gem_prefix, query = nil, &printer) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/glimmer/rake_task/list.rb', line 64

def list_gems(gem_prefix, query=nil, &printer)
  lines = `gem search -d #{gem_prefix}`.split("\n")
  gems = lines.slice_before {|l| l.match(REGEX_GEM_LINE) }.to_a
  gems = gems.map do |gem|
    {
      name: gem[0].match(REGEX_GEM_LINE)[1],
      version: gem[0].match(REGEX_GEM_LINE)[2],
      author: gem[1].strip,
      description: gem[4..-1]&.map(&:strip)&.join(' ').to_s
    }
  end.select do |gem|
    query.nil? || "#{gem[:name]} #{gem[:author]} #{gem[:description]}".downcase.include?(query.to_s.downcase)
  end
  printer.call(tablify(gem_prefix, gems))
end

.tablify(gem_prefix, gems) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/glimmer/rake_task/list.rb', line 80

def tablify(gem_prefix, gems)
  array_of_arrays = gems.map do |gem|
    name, namespace = gem[:name].sub(gem_prefix, '').underscore.titlecase.split
    human_name = name
    human_name += " (#{namespace})" unless namespace.nil?
    [
      human_name,
      gem[:name],
      gem[:version],
      gem[:author].sub('Author: ', ''),
      gem[:description],
    ]
  end
  Text::Table.new(
    :head => %w[Name Gem Version Author Description],
    :rows => array_of_arrays,
    :horizontal_padding    => 1,
    :vertical_boundary     => ' ',
    :horizontal_boundary   => ' ',
    :boundary_intersection => ' '
  )
end