Module: Label

Defined in:
lib/label.rb,
lib/label/version.rb,
lib/label/gemspec_info.rb,
lib/label/summary_extractor.rb,
lib/label/description_formatter.rb

Defined Under Namespace

Classes: DescriptionFormatter, GemspecInfo, SummaryExtractor

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.describe(gem, source = { rubygems: true }) ⇒ Object

Describe the given gem.

gem - A String describing the name of a gem. source - A hash with the gem source options, posible values:

- rubygems
- github
- path
- git

Returns a String.



89
90
91
92
93
94
95
96
# File 'lib/label.rb', line 89

def describe gem, source = { rubygems: true }
  if source[:rubygems]
    Gems.info(gem).fetch "info"
  else
    info = GemspecInfo.new gem, source
    info.summary
  end
end

.label(gemfile = "Gemfile") ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/label.rb', line 12

def label gemfile = "Gemfile"
  describing = lambda { |gem| STDOUT.write "#{gem}: " }
  described  = lambda { |description| STDOUT.puts description }

  output = process gemfile, describing, described

  write gemfile, output
end

.process(gemfile, describing = nil, described = nil) ⇒ Object

Process the given Gemfile.

gemfile - A String describing the path to a Gemfile. describing - A Proc to be called once a query to describe a gem begins.

Receives the name of the gem as an argument.

described - A Proc to be called once a query to describe a gem completes.

Receives the description as an argument.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/label.rb', line 28

def process gemfile, describing = nil, described = nil
  file = read gemfile

  lines = file.read.split "\n"

  processed_lines = []

  lines.each_with_index do |line, i|
    matches = line.match /^( *)gem ['"](.+?)['"]/

    if matches
      previous_line = lines[i - 1]

      whitespace = matches[1]
      gem        = matches[2]
      source     = extract_source_and_options line

      unless previous_line =~ /^ *#/
        describing.call gem if describing

        description = describe gem, source

        described.call description if described

        processed_lines << format(description, "#{whitespace}#")
      end
    end

    processed_lines << line
  end

  processed_lines.join("\n") + "\n"
end

.read(file) ⇒ Object

Read the given file.

file - A String describing the path to a file.



65
66
67
# File 'lib/label.rb', line 65

def read file
  File.open file
end

.write(file, text) ⇒ Object

Write to the given file.

file - A String describing the path to a file. text - A String describing text to be written.



73
74
75
76
77
# File 'lib/label.rb', line 73

def write file, text
  File.open file, "w" do |file|
    file.write text
  end
end