label 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43ed0e2234e5085642a6d2982e90208b061528ee
4
- data.tar.gz: 182735232dd5c93b31ce73606a8f752535936dab
3
+ metadata.gz: 25dc28997376d566445cf8c15d3151daa408eda7
4
+ data.tar.gz: c122b3799a49542703ac11ba550820f0d21d8f69
5
5
  SHA512:
6
- metadata.gz: 8565ec03ab01d7359743013922887c23bddac3b37e8de477c82dcb5df9346bcc078322e1fae46792be8bbdc1044925019d981fb481832d63c1b596d8fe1c2c31
7
- data.tar.gz: 8d12c99cbafc397a45b15ee50b744e004d57fbd1fec91596db35a5c77632dafc44ddfa073ec29a125d1626df02f5531f2507ab6538e803211572de02de3ea532
6
+ metadata.gz: 510ef82eab2b5627931e647aa4edf68dd0f01f83c45c27204897dc9cc34b95df36fb6c7affa1d19785cc990fc3374b4b5a0d9dfd01771e7b26771b95364c7330
7
+ data.tar.gz: 9ae86f37ba891fed191a76180f190ac79989ff9d7101e653cc227b81665258bc5d9a0b9faf421b67565fc1e5edb5eb1c55b1879281ddf462e556d95c8192079b
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/AUTHORS.md CHANGED
@@ -1,3 +1,4 @@
1
- Label is written and maintained by Johannes Gorset and various contributors:
1
+ Label is written and maintained by [Johannes Gorset](https://github.com/jgorset) and various contributors:
2
2
 
3
- * Felipe Espinoza
3
+ * [Felipe Espinoza](https://github.com/fespinoza)
4
+ * [Tim Kurvers](https://github.com/timkurvers)
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in label.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Label
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/label.svg)](https://rubygems.org/gems/label)
4
+ [![Build Status](https://img.shields.io/travis/jgorset/label.svg)](https://travis-ci.org/jgorset/label)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/jgorset/label.svg)](https://gemnasium.com/jgorset/label)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/jgorset/label.svg)](https://codeclimate.com/github/jgorset/label)
7
+ [![Coverage Status](https://img.shields.io/coveralls/jgorset/label.svg)](https://coveralls.io/r/jgorset/label)
8
+
3
9
  Label labels the gems in your Gemfile.
4
10
 
5
11
  ## Installation
@@ -8,17 +14,13 @@ Label labels the gems in your Gemfile.
8
14
 
9
15
  ## Usage
10
16
 
11
- $ cd /path/to/Gemfile
12
- $ label
17
+ ```zsh
18
+ $ label
19
+ ```
13
20
 
14
21
  ```ruby
15
- # /path/to/Gemfile
16
-
17
22
  source 'http://rubygems.org'
18
23
 
19
- # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
20
- gem 'rails', '4.0.0'
21
-
22
24
  # Flexible authentication solution for Rails with Warden
23
25
  gem 'devise'
24
26
 
@@ -31,10 +33,11 @@ gem 'carrierwave'
31
33
  gem 'rails_admin'
32
34
  ```
33
35
 
34
- Oh, and let's be real; you will always want to use label.
36
+ Label will look for a `Gemfile` in your current working directory by default, but you can
37
+ tell it to look somewhere else if you like:
35
38
 
36
- ```bash
37
- alias bundle="bundle && label"
39
+ ```zsh
40
+ $ label /path/to/Gemfile
38
41
  ```
39
42
 
40
43
  ## I love you
data/bin/label CHANGED
@@ -2,4 +2,8 @@
2
2
 
3
3
  require "label"
4
4
 
5
- Label.label
5
+ if ARGV.any?
6
+ Label.label ARGV.first
7
+ else
8
+ Label.label
9
+ end
data/lib/label.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "label/version"
2
2
  require "label/gemspec_info"
3
+ require "label/description_formatter"
3
4
  require "optparse"
4
5
  require "ostruct"
5
6
  require "gems"
@@ -8,12 +9,10 @@ module Label
8
9
 
9
10
  class << self
10
11
 
11
- def label
12
+ def label gemfile = "Gemfile"
12
13
  describing = lambda { |gem| STDOUT.write "#{gem}: " }
13
14
  described = lambda { |description| STDOUT.puts description }
14
15
 
15
- gemfile = "Gemfile"
16
-
17
16
  output = process gemfile, describing, described
18
17
 
19
18
  write gemfile, output
@@ -50,7 +49,7 @@ module Label
50
49
 
51
50
  described.call description if described
52
51
 
53
- processed_lines << "#{whitespace}# #{description}"
52
+ processed_lines << format(description, "#{whitespace}#")
54
53
  end
55
54
  end
56
55
 
@@ -98,6 +97,10 @@ module Label
98
97
 
99
98
  private
100
99
 
100
+ def format description, prepend_string
101
+ DescriptionFormatter.format description, prepend_string
102
+ end
103
+
101
104
  # Exctract the source options form a Gemfile gem declaration
102
105
  # as :github, :path and/or :branch and return a Hash with those options
103
106
  # :rubygems is the default
@@ -0,0 +1,48 @@
1
+ module Label
2
+ class DescriptionFormatter
3
+
4
+ FIRST_SENTENCE_REGEXP = /(?<first_sentence>([^.]*https?:\/\/[^\s]*\..*\..*)|([^.]*\.))(?<rest>.*)/
5
+ CHARACTERS_PER_LINE = 90
6
+
7
+ # Formats a description
8
+ #
9
+ # description - A description String to be formatted.
10
+ # separator - A String to be used as aditional separator formatting
11
+ def self.format description, separator = ''
12
+ if md = description.match(FIRST_SENTENCE_REGEXP)
13
+ break_in_lines md[:first_sentence].strip, separator
14
+ else
15
+ "#{separator} #{description}"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ # split lines that are too long in multiple lines
22
+ def self.break_in_lines description, separator = ''
23
+ description.gsub!(/\n/, ' ')
24
+ description = "#{separator} #{description}"
25
+
26
+ index = CHARACTERS_PER_LINE
27
+ while description.length > index
28
+ index = previous_space_index description, index
29
+ new_line_string = "\n#{separator} "
30
+ description[index] = new_line_string
31
+ index += CHARACTERS_PER_LINE + new_line_string.length
32
+ end
33
+ description
34
+ end
35
+
36
+ # given a string returns and an index returns the index of the first previous
37
+ # space character in the given string
38
+ def self.previous_space_index description, index
39
+ limit_char = description[index]
40
+ while limit_char != ' '
41
+ index -= 1
42
+ limit_char = description[index]
43
+ end
44
+ index
45
+ end
46
+ end
47
+
48
+ end
@@ -6,7 +6,7 @@ module Label
6
6
  STRING_REGEXPS = [
7
7
  /\"(?<content>[^"]*)\"/,
8
8
  /'(?<content>[^']*)'/,
9
- /%q\{(?<content>[^}]*)\}/,
9
+ /%q\{(?<content>[^}]*)\}/i
10
10
  ]
11
11
 
12
12
  def initialize content
@@ -14,7 +14,7 @@ module Label
14
14
  end
15
15
 
16
16
  def extract_summary
17
- STRING_REGEXPS.each do |regexp|
17
+ STRING_REGEXPS.find do |regexp|
18
18
  md = content.match(/\w+\.summary\s+=\s+#{regexp}/)
19
19
  return md[:content] if md
20
20
  end
data/lib/label/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Label
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -6,9 +6,22 @@ gem 'rails', '4.0.0'
6
6
  # Authentication
7
7
  gem 'devise'
8
8
 
9
- # Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
9
+ # Upload files in your Ruby applications, map them to a range of ORMs, store them on
10
+ # different backends.
10
11
  gem 'carrierwave'
11
12
 
13
+ # Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser.
14
+ gem 'nokogiri'
15
+ # Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
16
+ gem 'pg'
17
+
18
+ group :production do
19
+ # \Unicorn is an HTTP server for Rack applications designed to only serve fast clients
20
+ # on low-latency, high-bandwidth connections and take advantage of features in
21
+ # Unix/Unix-like kernels.
22
+ gem 'unicorn'
23
+ end
24
+
12
25
  group :test do
13
26
  # BDD for Ruby
14
27
  gem 'rspec'
@@ -8,6 +8,13 @@ gem 'devise'
8
8
 
9
9
  gem 'carrierwave'
10
10
 
11
+ gem 'nokogiri'
12
+ gem 'pg'
13
+
14
+ group :production do
15
+ gem 'unicorn'
16
+ end
17
+
11
18
  group :test do
12
19
  gem 'rspec'
13
20
  # Guard is a command line tool to easily handle events on file system modifications.
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require 'label/description_formatter'
3
+
4
+ def format input_string, prepend_string = "#"
5
+ Label::DescriptionFormatter.format input_string, prepend_string
6
+ end
7
+
8
+ describe Label::DescriptionFormatter do
9
+
10
+ describe '.format' do
11
+ it 'does not change descriptions that are not that long' do
12
+ description = "An IRB alternative and runtime developer console"
13
+ expect(format(description)).to eq "# #{description}"
14
+ end
15
+
16
+ context 'with long descriptions' do
17
+ it 'returns the first sentence (ended by ".") for long descriptions' do
18
+ long_description = "Nokogiri (é\u008B¸) is an HTML, XML, SAX, and Reader "+
19
+ "parser. Among Nokogiri's\nmany features is the "+
20
+ "ability to search documents via XPath or CSS3 "+
21
+ "selectors.\n\nXML is like violence - if it "+
22
+ "doesnâ\u0080\u0099t solve your problems, you are not"+
23
+ "using\nenough of it."
24
+ result = format(long_description)
25
+ expect(result).to eq "# Nokogiri (é\u008B¸) is an HTML, XML, SAX, and Reader parser."
26
+ end
27
+
28
+ it 'returns the first sentence an include urls correctly' do
29
+ long_description = "Pg is the Ruby interface to the {PostgreSQL RDBMS}"+
30
+ "[http://www.postgresql.org/].\n\nIt works with {PostgreSQL 8.4 and later}"+
31
+ "[http://www.postgresql.org/support/versioning/].\n\nA small example usage:\n\n"+
32
+ " #!/usr/bin/env ruby\n\n require 'pg'\n\n# Output a table of current "+
33
+ "connections to the DB\n conn =PG.connect( dbname: 'sales' )\n conn.exec("+
34
+ " \"SELECT * FROM pg_stat_activity\" ) do |result|\n puts \" PID |"+
35
+ " User | Query\"\n result.each do|row|\n puts \" %7d |"+
36
+ " %-16s | %s \" %\nrow.values_at('procpid', 'usename', 'current_query')\n"+
37
+ " end\n end"
38
+ result = format long_description, '#'
39
+ expect(result).to eq "# Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]."
40
+ end
41
+
42
+ it 'returns the first sentence in multiple lines when this is too long' do
43
+ long_description = "\\Unicorn is an HTTP server for Rack applications "+
44
+ "designed to only serve\nfast clients on low-latency, high-bandwidth "+
45
+ "connections and take\nadvantage of features in Unix/Unix-like kernels."+
46
+ "Slow clients should\nonly be served by placing a reverse proxy capable"+
47
+ " of fully buffering\nboth the the request and response in between "+
48
+ "\\Unicorn and slow clients."
49
+
50
+ expected_description = " # \\Unicorn is an HTTP server for Rack applications "+
51
+ "designed to only serve fast clients\n # on low-latency, high-bandwidth "+
52
+ "connections and take advantage of features in\n # Unix/Unix-like kernels."
53
+ expect(format(long_description, ' #')).to eq expected_description
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -28,11 +28,22 @@ describe Label::SummaryExtractor do
28
28
  include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my 'projects'"
29
29
  end
30
30
 
31
+ context "for strings defined with %Q{}" do
32
+ let(:content) { "s.email = [\"fespinozacast@gmail.com\"]\n s.homepage = \"fespinoza.github.io\"\n s.summary = %Q{A series of generators an other rails \"defaults\" for my 'projects'}\n s.description = \"TODO.\"\n s.license = \"MIT\"\n\n" }
33
+
34
+ include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my 'projects'"
35
+ end
36
+
31
37
  context "for different gem configuration variable names" do
32
38
  let(:content) { "g.email = [\"fespinozacast@gmail.com\"]\n g.homepage = \"fespinoza.github.io\"\n g.summary = %q{A series of generators an other rails \"defaults\" for my 'projects'}\n g.description = \"TODO.\"\n g.license = \"MIT\"\n\n" }
33
39
 
34
40
  include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my 'projects'"
35
41
  end
36
42
 
43
+ context "for summaries that don't exist at all" do
44
+ let(:content) { "s.email = [\"fespinozacast@gmail.com\"]\n s.homepage = \"fespinoza.github.io\"\n s.description = \"TODO.\"\n s.license = \"MIT\"\n\n" }
45
+
46
+ include_examples "extracts summary", nil
47
+ end
37
48
  end
38
49
  end
data/spec/label_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  describe Label do
@@ -16,6 +17,35 @@ describe Label do
16
17
  "Label labels the gems in your Gemfile"
17
18
  )
18
19
 
20
+ allow(subject).to receive(:describe).with("pg", rubygems: true).and_return(
21
+ "Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].\n\n"+
22
+ "It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/]."+
23
+ "\n\nA small example usage:\n\n #!/usr/bin/env ruby\n\n require 'pg'\n\n"+
24
+ "# Output a table of current connections to the DB\n conn ="+
25
+ "PG.connect( dbname: 'sales' )\n conn.exec( \"SELECT * FROM pg_stat_activity\" )"+
26
+ "do |result|\n puts \" PID | User | Query\"\n result.each do"+
27
+ "|row|\n puts \" %7d | %-16s | %s \" %\n"+
28
+ "row.values_at('procpid', 'usename', 'current_query')\n end\n end"
29
+ )
30
+
31
+ allow(subject).to receive(:describe).with("nokogiri", rubygems: true).and_return(
32
+ "Nokogiri (é\u008B¸) is an HTML, XML, SAX, and Reader "+
33
+ "parser. Among Nokogiri's\nmany features is the "+
34
+ "ability to search documents via XPath or CSS3 "+
35
+ "selectors.\n\nXML is like violence - if it "+
36
+ "doesnâ\u0080\u0099t solve your problems, you are not"+
37
+ "using\nenough of it."
38
+ )
39
+
40
+ allow(subject).to receive(:describe).with("unicorn", rubygems: true).and_return(
41
+ "\\Unicorn is an HTTP server for Rack applications "+
42
+ "designed to only serve\nfast clients on low-latency, high-bandwidth "+
43
+ "connections and take\nadvantage of features in Unix/Unix-like kernels."+
44
+ "Slow clients should\nonly be served by placing a reverse proxy capable"+
45
+ " of fully buffering\nboth the the request and response in between "+
46
+ "\\Unicorn and slow clients."
47
+ )
48
+
19
49
  allow(subject).to receive(:describe).with("pry", github: "pry/pry", branch: "development")
20
50
  .and_return("An IRB alternative and runtime developer console")
21
51
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "label"
2
2
 
3
+ require "coveralls"
4
+ Coveralls.wear!
5
+
3
6
  def fixture file
4
7
  File.read "spec/fixtures/#{file}"
5
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: label
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Gorset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gems
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - .gitignore
78
+ - .travis.yml
78
79
  - AUTHORS.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
@@ -83,11 +84,13 @@ files:
83
84
  - bin/label
84
85
  - label.gemspec
85
86
  - lib/label.rb
87
+ - lib/label/description_formatter.rb
86
88
  - lib/label/gemspec_info.rb
87
89
  - lib/label/summary_extractor.rb
88
90
  - lib/label/version.rb
89
91
  - spec/fixtures/processed_gemfile
90
92
  - spec/fixtures/stock_gemfile
93
+ - spec/label/description_formatter_spec.rb
91
94
  - spec/label/gemspec_info_spec.rb
92
95
  - spec/label/summary_extractor_spec.rb
93
96
  - spec/label_spec.rb
@@ -119,7 +122,9 @@ summary: Label labels the gems in your Gemfile
119
122
  test_files:
120
123
  - spec/fixtures/processed_gemfile
121
124
  - spec/fixtures/stock_gemfile
125
+ - spec/label/description_formatter_spec.rb
122
126
  - spec/label/gemspec_info_spec.rb
123
127
  - spec/label/summary_extractor_spec.rb
124
128
  - spec/label_spec.rb
125
129
  - spec/spec_helper.rb
130
+ has_rdoc: