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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in add_gem.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "mocha", "~> 0.12.3", :require => false
8
+ end
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
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
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,7 @@
1
+ require "add_gem/add_gem"
2
+
3
+ module AddGem
4
+ def self.add(gem_name)
5
+ AddGem.add(gem_name)
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module AddGem
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require "mocha"
3
+
4
+ require 'add_gem'
5
+
6
+ class AddGemTest < Test::Unit::TestCase
7
+
8
+ def test_write_to_gemfile
9
+ assert true
10
+ end
11
+ 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