add_gem 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README.md +26 -0
- data/Rakefile +10 -0
- data/add_gem.gemspec +16 -0
- data/bin/add_gem +18 -0
- data/lib/add_gem.rb +7 -0
- data/lib/add_gem/add_gem.rb +39 -0
- data/lib/add_gem/version.rb +3 -0
- data/test/test_add_gem.rb +11 -0
- metadata +58 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Adolfo Builes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# AddGem
|
2
|
+
|
3
|
+
Command-line tool to append new gems to your Gemfile.
|
4
|
+
|
5
|
+
## Problem
|
6
|
+
When adding a new gem to my Gemfile I found myself visiting
|
7
|
+
http://rubygems.org/gems/GEM_NAME and checking the latest version.
|
8
|
+
|
9
|
+
I built this tool so I give the name of the gem and it adds the gem to
|
10
|
+
my Gemfile and includes the version using `~>`.
|
11
|
+
|
12
|
+
What's wrong with `gem search rails -r` you might be thinking? the
|
13
|
+
answer is nothing, but why do something in more than one step when it
|
14
|
+
can be done in one. :)
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Install using rubygems:
|
20
|
+
|
21
|
+
gem 'add_gem'
|
22
|
+
|
23
|
+
And then execute on your work directory:
|
24
|
+
|
25
|
+
$ add_gem rails
|
26
|
+
$ Added gem "rails", "~> 3.2.8" to your Gemfile.
|
data/Rakefile
ADDED
data/add_gem.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../lib/add_gem/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Adolfo Builes"]
|
5
|
+
gem.email = ["builes.adolfo@gmail.com"]
|
6
|
+
gem.description = %q{"Command-line tool to append new gems to your Gemfile."}
|
7
|
+
gem.summary = %q{"Command-line tool to append new gems to your Gemfile."}
|
8
|
+
gem.homepage = "https://github.com/abuiles/add_gem"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = "add_gem"
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "add_gem"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = AddGem::VERSION
|
16
|
+
end
|
data/bin/add_gem
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'add_gem'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
opt_parser = OptionParser.new do |opt|
|
9
|
+
opt.banner = "Usage: add_gem GEM_NAME"
|
10
|
+
end
|
11
|
+
|
12
|
+
opt_parser.parse!
|
13
|
+
|
14
|
+
if not (gem_name =ARGV[0]).nil?
|
15
|
+
AddGem.add(gem_name)
|
16
|
+
else
|
17
|
+
puts opt_parser
|
18
|
+
end
|
data/lib/add_gem.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
module AddGem
|
4
|
+
module AddGem
|
5
|
+
extend self
|
6
|
+
BASE_URL = "https://rubygems.org/api/v1/gems"
|
7
|
+
|
8
|
+
def add(gem_name)
|
9
|
+
url = "#{BASE_URL}/#{gem_name}.json"
|
10
|
+
gem_info = get_gem(url)
|
11
|
+
|
12
|
+
if gem_info
|
13
|
+
gem_entry = "gem \"#{gem_name}\", \"~> #{gem_info["version"]}\""
|
14
|
+
f= File.open('Gemfile', 'a+'){ |f| f.puts gem_entry }
|
15
|
+
puts "Added #{gem_entry} to your Gemfile."
|
16
|
+
else
|
17
|
+
puts "Opps something went wrong fetching the gem information.\nTry curl #{url}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_gem(gem_url)
|
22
|
+
uri = URI(gem_url)
|
23
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
24
|
+
http.use_ssl = true
|
25
|
+
|
26
|
+
response = http.start do |h|
|
27
|
+
h.request( Net::HTTP::Get.new(uri.request_uri) )
|
28
|
+
end
|
29
|
+
|
30
|
+
case response
|
31
|
+
when Net::HTTPSuccess
|
32
|
+
JSON.parse(response.body)
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: add_gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adolfo Builes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! '"Command-line tool to append new gems to your Gemfile."'
|
15
|
+
email:
|
16
|
+
- builes.adolfo@gmail.com
|
17
|
+
executables:
|
18
|
+
- add_gem
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- add_gem.gemspec
|
28
|
+
- bin/add_gem
|
29
|
+
- lib/add_gem.rb
|
30
|
+
- lib/add_gem/add_gem.rb
|
31
|
+
- lib/add_gem/version.rb
|
32
|
+
- test/test_add_gem.rb
|
33
|
+
homepage: https://github.com/abuiles/add_gem
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: ! '"Command-line tool to append new gems to your Gemfile."'
|
57
|
+
test_files:
|
58
|
+
- test/test_add_gem.rb
|