label 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHORS.md +3 -0
- data/README.md +6 -0
- data/Rakefile +5 -0
- data/lib/label.rb +33 -5
- data/lib/label/gemspec_info.rb +76 -0
- data/lib/label/summary_extractor.rb +23 -0
- data/lib/label/version.rb +1 -1
- data/spec/fixtures/processed_gemfile +7 -0
- data/spec/fixtures/stock_gemfile +5 -0
- data/spec/label/gemspec_info_spec.rb +25 -0
- data/spec/label/summary_extractor_spec.rb +38 -0
- data/spec/label_spec.rb +15 -3
- data/spec/spec_helper.rb +7 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ed0e2234e5085642a6d2982e90208b061528ee
|
4
|
+
data.tar.gz: 182735232dd5c93b31ce73606a8f752535936dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8565ec03ab01d7359743013922887c23bddac3b37e8de477c82dcb5df9346bcc078322e1fae46792be8bbdc1044925019d981fb481832d63c1b596d8fe1c2c31
|
7
|
+
data.tar.gz: 8d12c99cbafc397a45b15ee50b744e004d57fbd1fec91596db35a5c77632dafc44ddfa073ec29a125d1626df02f5531f2507ab6538e803211572de02de3ea532
|
data/AUTHORS.md
ADDED
data/README.md
CHANGED
@@ -31,6 +31,12 @@ gem 'carrierwave'
|
|
31
31
|
gem 'rails_admin'
|
32
32
|
```
|
33
33
|
|
34
|
+
Oh, and let's be real; you will always want to use label.
|
35
|
+
|
36
|
+
```bash
|
37
|
+
alias bundle="bundle && label"
|
38
|
+
```
|
39
|
+
|
34
40
|
## I love you
|
35
41
|
|
36
42
|
Johannes Gorset made this. You should [tweet me](http://twitter.com/jgorset) if you can't get
|
data/Rakefile
CHANGED
data/lib/label.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "label/version"
|
2
|
+
require "label/gemspec_info"
|
2
3
|
require "optparse"
|
3
4
|
require "ostruct"
|
4
5
|
require "gems"
|
@@ -17,7 +18,7 @@ module Label
|
|
17
18
|
|
18
19
|
write gemfile, output
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
# Process the given Gemfile.
|
22
23
|
#
|
23
24
|
# gemfile - A String describing the path to a Gemfile.
|
@@ -40,11 +41,12 @@ module Label
|
|
40
41
|
|
41
42
|
whitespace = matches[1]
|
42
43
|
gem = matches[2]
|
44
|
+
source = extract_source_and_options line
|
43
45
|
|
44
46
|
unless previous_line =~ /^ *#/
|
45
47
|
describing.call gem if describing
|
46
48
|
|
47
|
-
description = describe gem
|
49
|
+
description = describe gem, source
|
48
50
|
|
49
51
|
described.call description if described
|
50
52
|
|
@@ -77,11 +79,37 @@ module Label
|
|
77
79
|
|
78
80
|
# Describe the given gem.
|
79
81
|
#
|
80
|
-
# gem
|
82
|
+
# gem - A String describing the name of a gem.
|
83
|
+
# source - A hash with the gem source options, posible values:
|
84
|
+
# - rubygems
|
85
|
+
# - github
|
86
|
+
# - path
|
87
|
+
# - git
|
81
88
|
#
|
82
89
|
# Returns a String.
|
83
|
-
def describe gem
|
84
|
-
|
90
|
+
def describe gem, source = { rubygems: true }
|
91
|
+
if source[:rubygems]
|
92
|
+
Gems.info(gem).fetch "info"
|
93
|
+
else
|
94
|
+
info = GemspecInfo.new gem, source
|
95
|
+
info.summary
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
# Exctract the source options form a Gemfile gem declaration
|
102
|
+
# as :github, :path and/or :branch and return a Hash with those options
|
103
|
+
# :rubygems is the default
|
104
|
+
def extract_source_and_options line
|
105
|
+
source = {}
|
106
|
+
options = line.split ","
|
107
|
+
options[1, options.length - 1].each do |option|
|
108
|
+
args = option.split(":").map {|arg| arg.strip.gsub(/('|\")/, '') }
|
109
|
+
source[args.first.to_sym] = args.last
|
110
|
+
end
|
111
|
+
source[:rubygems] = true if source.empty?
|
112
|
+
source
|
85
113
|
end
|
86
114
|
|
87
115
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'label/summary_extractor'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Label
|
5
|
+
# A class to represent a gemspec file in order
|
6
|
+
# to extract info from it
|
7
|
+
class GemspecInfo
|
8
|
+
attr_reader :gem_name, :source
|
9
|
+
|
10
|
+
GITHUB_RAW_URL = "https://raw.githubusercontent.com"
|
11
|
+
|
12
|
+
def initialize gem_name, source
|
13
|
+
@gem_name = gem_name
|
14
|
+
@source = source
|
15
|
+
end
|
16
|
+
|
17
|
+
# Extracts the gemspec summary string
|
18
|
+
def summary
|
19
|
+
SummaryExtractor.new(content).extract_summary
|
20
|
+
end
|
21
|
+
|
22
|
+
# Raw contents of the gemspec file
|
23
|
+
def content
|
24
|
+
@content ||= fetch_gemspec_content!
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Fetch the content from a gemspec file that could be remote or
|
30
|
+
# that could be a file in the developer computer
|
31
|
+
#
|
32
|
+
# Returns a string with the gemspec file content
|
33
|
+
def fetch_gemspec_content!
|
34
|
+
case source_name
|
35
|
+
when :git
|
36
|
+
fetch_gemspec_content_from_git!
|
37
|
+
when :github
|
38
|
+
fetch_gemspec_content_from_github!
|
39
|
+
when :path
|
40
|
+
fetch_gemspec_content_from_path!
|
41
|
+
else
|
42
|
+
""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# returns a symbol of the defined source
|
47
|
+
# it could be :git, :github, :path, etc
|
48
|
+
def source_name
|
49
|
+
[:git, :github, :path].each do |source_name|
|
50
|
+
return source_name if source[source_name]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# for simplicity git protocol calls that match with a github repo
|
55
|
+
# will be converted to a github url
|
56
|
+
def fetch_gemspec_content_from_git!
|
57
|
+
if md = source[:git].match(/git:\/\/github\.com:(?<repo>.*)/)
|
58
|
+
source[:github] = md[:repo]
|
59
|
+
source.delete :git
|
60
|
+
fetch_gemspec_content_from_github!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch_gemspec_content_from_github!
|
65
|
+
repo = source[:github]
|
66
|
+
branch = source[:branch] || "master"
|
67
|
+
file_url = "#{GITHUB_RAW_URL}/#{repo}/#{branch}/#{gem_name}.gemspec"
|
68
|
+
Net::HTTP.get_response(URI(file_url)).body
|
69
|
+
end
|
70
|
+
|
71
|
+
def fetch_gemspec_content_from_path!
|
72
|
+
File.readlines("#{source[:path]}/#{gem_name}.gemspec").join "\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Label
|
2
|
+
# A class to extract the summary from the contents of a gemspec file
|
3
|
+
class SummaryExtractor
|
4
|
+
attr_reader :content
|
5
|
+
|
6
|
+
STRING_REGEXPS = [
|
7
|
+
/\"(?<content>[^"]*)\"/,
|
8
|
+
/'(?<content>[^']*)'/,
|
9
|
+
/%q\{(?<content>[^}]*)\}/,
|
10
|
+
]
|
11
|
+
|
12
|
+
def initialize content
|
13
|
+
@content = content
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract_summary
|
17
|
+
STRING_REGEXPS.each do |regexp|
|
18
|
+
md = content.match(/\w+\.summary\s+=\s+#{regexp}/)
|
19
|
+
return md[:content] if md
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/label/version.rb
CHANGED
@@ -15,3 +15,10 @@ group :test do
|
|
15
15
|
# Guard is a command line tool to easily handle events on file system modifications.
|
16
16
|
gem 'guard'
|
17
17
|
end
|
18
|
+
|
19
|
+
group :development
|
20
|
+
# Label labels the gems in your Gemfile
|
21
|
+
gem 'label', path: './'
|
22
|
+
# An IRB alternative and runtime developer console
|
23
|
+
gem 'pry', github: 'pry/pry', branch: 'development'
|
24
|
+
end
|
data/spec/fixtures/stock_gemfile
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "label/gemspec_info"
|
3
|
+
|
4
|
+
describe Label::GemspecInfo do
|
5
|
+
|
6
|
+
describe "#summary" do
|
7
|
+
it "should extract the summary from a gem from a github repo" do
|
8
|
+
mock_github_response!
|
9
|
+
info = Label::GemspecInfo.new "label", github: "jgorset/label"
|
10
|
+
expect(info.summary).to eq "Label labels the gems in your Gemfile"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should extract the summary from a gem from a git repo" do
|
14
|
+
mock_github_response!
|
15
|
+
info = Label::GemspecInfo.new "label", git: "git://github.com:jgorset/label"
|
16
|
+
expect(info.summary).to eq "Label labels the gems in your Gemfile"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should extract the summary from a gem from a path" do
|
20
|
+
info = Label::GemspecInfo.new "label", path: "./"
|
21
|
+
expect(info.summary).to eq "Label labels the gems in your Gemfile"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "label/summary_extractor"
|
2
|
+
|
3
|
+
shared_examples "extracts summary" do |expected_summary|
|
4
|
+
it "should extract summary" do
|
5
|
+
extractor = Label::SummaryExtractor.new(content)
|
6
|
+
expect(extractor.extract_summary).to eq expected_summary
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Label::SummaryExtractor do
|
11
|
+
|
12
|
+
describe "#extract_summary" do
|
13
|
+
context "for double quoted strings containing single quoted strings" do
|
14
|
+
let(:content) { "s.email = [\"fespinozacast@gmail.com\"]\n s.homepage = \"fespinoza.github.io\"\n s.summary = \"A series of generators an other rails 'defaults' for my projects\"\n s.description = \"TODO.\"\n s.license = \"MIT\"\n\n" }
|
15
|
+
|
16
|
+
include_examples "extracts summary", "A series of generators an other rails 'defaults' for my projects"
|
17
|
+
end
|
18
|
+
|
19
|
+
context "for single quoted strings containing double quoted strings" do
|
20
|
+
let(:content) { "s.email = [\"fespinozacast@gmail.com\"]\n s.homepage = \"fespinoza.github.io\"\n s.summary = 'A series of generators an other rails \"defaults\" for my projects'\n s.description = \"TODO.\"\n s.license = \"MIT\"\n\n" }
|
21
|
+
|
22
|
+
include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my projects"
|
23
|
+
end
|
24
|
+
|
25
|
+
context "for strings defined with %q{}" do
|
26
|
+
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" }
|
27
|
+
|
28
|
+
include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my 'projects'"
|
29
|
+
end
|
30
|
+
|
31
|
+
context "for different gem configuration variable names" do
|
32
|
+
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
|
+
|
34
|
+
include_examples "extracts summary", "A series of generators an other rails \"defaults\" for my 'projects'"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/spec/label_spec.rb
CHANGED
@@ -5,13 +5,20 @@ describe Label do
|
|
5
5
|
it "should label unlabelled gems" do
|
6
6
|
allow(File).to receive(:open).with("Gemfile").and_return(StringIO.new fixture("stock_gemfile"))
|
7
7
|
|
8
|
-
allow(subject).to receive(:describe).with("rspec").and_return("BDD for Ruby")
|
8
|
+
allow(subject).to receive(:describe).with("rspec", rubygems: true).and_return("BDD for Ruby")
|
9
9
|
|
10
|
-
allow(subject).to receive(:describe).with("carrierwave").and_return(
|
11
|
-
"Upload files in your Ruby applications, map them to a range of ORMs, " +
|
10
|
+
allow(subject).to receive(:describe).with("carrierwave", rubygems: true).and_return(
|
11
|
+
"Upload files in your Ruby applications, map them to a range of ORMs, " +
|
12
12
|
"store them on different backends."
|
13
13
|
)
|
14
14
|
|
15
|
+
allow(subject).to receive(:describe).with("label", path: "./").and_return(
|
16
|
+
"Label labels the gems in your Gemfile"
|
17
|
+
)
|
18
|
+
|
19
|
+
allow(subject).to receive(:describe).with("pry", github: "pry/pry", branch: "development")
|
20
|
+
.and_return("An IRB alternative and runtime developer console")
|
21
|
+
|
15
22
|
expect(subject.process("Gemfile")).to eq fixture("processed_gemfile")
|
16
23
|
end
|
17
24
|
end
|
@@ -22,5 +29,10 @@ describe Label do
|
|
22
29
|
|
23
30
|
expect(subject.describe("label")).to eq "Label gems in your Gemfile"
|
24
31
|
end
|
32
|
+
|
33
|
+
it "should describe a given gem from a github source" do
|
34
|
+
mock_github_response!
|
35
|
+
expect(subject.describe("label", github: "jgorset/label")).to eq "Label labels the gems in your Gemfile"
|
36
|
+
end
|
25
37
|
end
|
26
38
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,3 +3,10 @@ require "label"
|
|
3
3
|
def fixture file
|
4
4
|
File.read "spec/fixtures/#{file}"
|
5
5
|
end
|
6
|
+
|
7
|
+
def mock_github_response!
|
8
|
+
gemspec_contents = File.readlines("./label.gemspec").join("\n")
|
9
|
+
response_double = double :response_double, body: gemspec_contents
|
10
|
+
expect(Net::HTTP).to receive(:get_response).with(anything())
|
11
|
+
.and_return(response_double)
|
12
|
+
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
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Gorset
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-05 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
|
+
- AUTHORS.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -82,9 +83,13 @@ files:
|
|
82
83
|
- bin/label
|
83
84
|
- label.gemspec
|
84
85
|
- lib/label.rb
|
86
|
+
- lib/label/gemspec_info.rb
|
87
|
+
- lib/label/summary_extractor.rb
|
85
88
|
- lib/label/version.rb
|
86
89
|
- spec/fixtures/processed_gemfile
|
87
90
|
- spec/fixtures/stock_gemfile
|
91
|
+
- spec/label/gemspec_info_spec.rb
|
92
|
+
- spec/label/summary_extractor_spec.rb
|
88
93
|
- spec/label_spec.rb
|
89
94
|
- spec/spec_helper.rb
|
90
95
|
homepage: https://github.com/jgorset/label
|
@@ -107,12 +112,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
112
|
version: '0'
|
108
113
|
requirements: []
|
109
114
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.2.2
|
111
116
|
signing_key:
|
112
117
|
specification_version: 4
|
113
118
|
summary: Label labels the gems in your Gemfile
|
114
119
|
test_files:
|
115
120
|
- spec/fixtures/processed_gemfile
|
116
121
|
- spec/fixtures/stock_gemfile
|
122
|
+
- spec/label/gemspec_info_spec.rb
|
123
|
+
- spec/label/summary_extractor_spec.rb
|
117
124
|
- spec/label_spec.rb
|
118
125
|
- spec/spec_helper.rb
|