toastyapps-gembox 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +1 -1
- data/bin/gembox +1 -1
- data/lib/gembox.rb +47 -27
- data/lib/templates/bashrc +2 -2
- data/lib/templates/dispatch.rb +100 -47
- data/lib/templates/gemrc +5 -3
- metadata +3 -3
data/History.txt
CHANGED
data/bin/gembox
CHANGED
data/lib/gembox.rb
CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
|
|
3
3
|
require 'erb'
|
4
4
|
|
5
5
|
class Gembox
|
6
|
-
VERSION = '1.3.
|
6
|
+
VERSION = '1.3.4'
|
7
7
|
attr_accessor :dir, :cfg, :box_name
|
8
8
|
|
9
9
|
def initialize
|
@@ -11,22 +11,22 @@ class Gembox
|
|
11
11
|
load_config
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
def help(args)
|
16
|
+
puts File.read("../README.textile")
|
16
17
|
end
|
17
|
-
|
18
|
-
def
|
18
|
+
|
19
|
+
def create(args)
|
19
20
|
args.each do |box_name|
|
20
21
|
@box_name = box_name
|
21
22
|
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
22
|
-
|
23
|
+
|
23
24
|
if File.exists?(@dir)
|
24
25
|
puts "Box #{box_name} already exists"
|
25
26
|
else
|
26
27
|
FileUtils.mkdir_p @dir # make gembox folder
|
27
28
|
FileUtils.mkdir_p "#{@dir}/usr/bin"
|
28
|
-
|
29
|
-
|
29
|
+
|
30
30
|
File.open("#{@dir}/.gemrc", 'w') { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/gemrc").read).result(binding) } unless File.exists?("#{@dir}/.gemrc")
|
31
31
|
File.open("#{@dir}/.bashrc", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/bashrc").read).result(binding) } unless File.exists?("#{@dir}/.bashrc")
|
32
32
|
File.open("#{@dir}/shell.bash", "w") {|f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/shell.bash").read).result(binding) } unless File.exists?("#{@dir}/shell.bash")
|
@@ -35,19 +35,15 @@ class Gembox
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
39
|
-
def
|
38
|
+
|
39
|
+
def list(args)
|
40
40
|
puts "Current Boxes:\n"
|
41
41
|
Dir.foreach("#{ENV['HOME']}/.gembox") do |file|
|
42
|
-
puts " #{file}" if file !~ /^\./
|
42
|
+
puts " #{file}" if file !~ /^\./ && File.directory?("#{ENV['HOME']}/.gembox/#{file}")
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
def
|
47
|
-
delete(args)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.delete(args)
|
45
|
+
|
46
|
+
def delete(args)
|
51
47
|
args.each do |box_name|
|
52
48
|
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
53
49
|
if File.exists?(@dir)
|
@@ -58,12 +54,8 @@ class Gembox
|
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
61
|
-
|
62
|
-
def
|
63
|
-
shell(args)
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.shell(args)
|
57
|
+
|
58
|
+
def shell(args)
|
67
59
|
box_name = args.shift
|
68
60
|
@dir = "#{ENV['HOME']}/.gembox/#{box_name}"
|
69
61
|
if File.exists?(@dir)
|
@@ -73,10 +65,10 @@ class Gembox
|
|
73
65
|
puts "Box #{box_name} does not exist"
|
74
66
|
end
|
75
67
|
end
|
76
|
-
|
68
|
+
|
77
69
|
private
|
78
|
-
|
79
|
-
def
|
70
|
+
|
71
|
+
def generate_gems_yaml(file)
|
80
72
|
data = `gem query -d`.split("\n")
|
81
73
|
gemdata = {}
|
82
74
|
index = 'NULL'
|
@@ -108,9 +100,37 @@ class Gembox
|
|
108
100
|
def load_config
|
109
101
|
@cfg = load_yaml(@cfg_path)
|
110
102
|
end
|
111
|
-
|
103
|
+
|
112
104
|
def load_yaml path
|
113
105
|
File.exists?(path) ? YAML.load(File.open(path)) : nil
|
114
106
|
end
|
115
107
|
|
108
|
+
def method_missing(method, args)
|
109
|
+
if method.to_s =~ /^--/
|
110
|
+
new_args = [method.to_s]
|
111
|
+
args.each do |arg|
|
112
|
+
if arg =~ /^--/
|
113
|
+
new_args << arg
|
114
|
+
else
|
115
|
+
method = arg
|
116
|
+
end
|
117
|
+
end
|
118
|
+
args = new_args
|
119
|
+
end
|
120
|
+
if !self.respond_to?(method)
|
121
|
+
@dir = "#{ENV['HOME']}/.gembox/#{method}"
|
122
|
+
if args.include?("--create")
|
123
|
+
create([method] << args.delete("--create"))
|
124
|
+
end
|
125
|
+
if File.exists?(@dir)
|
126
|
+
shell([method] << args)
|
127
|
+
end
|
128
|
+
else
|
129
|
+
self.send(method, args)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
alias_method :sh, :shell
|
134
|
+
alias_method :rm, :delete
|
135
|
+
alias_method :ls, :list
|
116
136
|
end
|
data/lib/templates/bashrc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PS1="gembox-<%= @box_name %>:\w> "
|
2
2
|
export PATH=<%= @dir %>/usr/bin:$PATH
|
3
3
|
alias gem='ruby <%= @dir %>/dispatch.rb'
|
4
|
-
export GEM_PATH=<%= @dir
|
5
|
-
export GEM_HOME=<%= @dir
|
4
|
+
export GEM_PATH=<%= @dir %>
|
5
|
+
export GEM_HOME=<%= @dir %>
|
6
6
|
|
7
7
|
ruby <%= @dir %>/dispatch.rb load_config
|
data/lib/templates/dispatch.rb
CHANGED
@@ -2,62 +2,115 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'yaml'
|
4
4
|
require 'fileutils'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
5
|
+
|
6
|
+
class Dispatch
|
7
|
+
|
8
|
+
DIR = "<%= @dir %>"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def install(args)
|
12
|
+
system("gem --config-file #{DIR}/.gemrc install --bindir #{DIR}/usr/bin #{ARGV.join(' ')}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_config(args)
|
16
|
+
cfg_path = "#{ENV['HOME']}/.gembox/config.yml"
|
17
|
+
if File.exists?(cfg_path)
|
18
|
+
data = YAML.load(File.open(cfg_path).read)
|
19
|
+
if data['symlink']
|
20
|
+
data['symlink'].each do |symlink|
|
21
|
+
if `gem query -i -n #{symlink}`.chomp == 'false'
|
22
|
+
system("ruby #{DIR}/dispatch.rb symlink #{symlink}")
|
23
|
+
end
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if data[gem_name] && data[gem_name].keys.length > 0
|
26
|
-
FileUtils.mkdir_p('<%= @dir %>/gems/gems/')
|
27
|
-
FileUtils.mkdir_p('<%= @dir %>/gems/specifications/')
|
28
|
+
|
29
|
+
def unsymlink(args)
|
30
|
+
gem_name = args.shift
|
31
|
+
data = `gem query -d -n #{gem_name}`.strip.split("\n")
|
28
32
|
versions = []
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
puts 'Select gem to symlink:'
|
33
|
-
index = 1
|
34
|
-
data[gem_name].keys.each do |key|
|
35
|
-
puts " #{index}. #{gem_name}-#{key}"
|
36
|
-
index += 1
|
33
|
+
data.each do |line|
|
34
|
+
if line =~ /^[a-z]/i
|
35
|
+
versions << line.match(/\((.*?)\)/).captures[0]
|
37
36
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if
|
42
|
-
|
37
|
+
end
|
38
|
+
if versions.length == 1
|
39
|
+
version = versions[0]
|
40
|
+
if `ls -la #{DIR}/gems/ | grep #{gem_name}-#{version}` =~ /^l/
|
41
|
+
`rm #{DIR}/gems/#{gem_name}-#{version} && rm #{DIR}/specifications/#{gem_name}-#{version}.gemspec`
|
42
|
+
puts "Gem #{gem_name} is been unsymlinked"
|
43
43
|
else
|
44
|
-
|
44
|
+
puts "Gem #{gem_name} is installed, but not symlinked"
|
45
45
|
end
|
46
|
+
elsif versions.length > 1
|
47
|
+
puts "more"
|
48
|
+
else
|
49
|
+
puts "Gem #{gem_name} is not installed"
|
46
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def symlink(args)
|
54
|
+
data = YAML.load(File.open("#{DIR}/gems.yaml").read)
|
55
|
+
args.each do |gem_name|
|
56
|
+
if data[gem_name] && data[gem_name].keys.length > 0
|
57
|
+
FileUtils.mkdir_p("#{DIR}/gems/")
|
58
|
+
FileUtils.mkdir_p("#{DIR}/specifications/")
|
59
|
+
versions = []
|
60
|
+
if data[gem_name].keys.length == 1
|
61
|
+
versions << data[gem_name].keys[0]
|
62
|
+
elsif data[gem_name].keys.length > 1
|
63
|
+
puts 'Select gem to symlink:'
|
64
|
+
index = 1
|
65
|
+
data[gem_name].keys.each do |key|
|
66
|
+
puts " #{index}. #{gem_name}-#{key}"
|
67
|
+
index += 1
|
68
|
+
end
|
69
|
+
puts " #{index}. All versions"
|
70
|
+
print "> "
|
71
|
+
choice = gets
|
72
|
+
if choice == index
|
73
|
+
versions = data[gem_name].keys
|
74
|
+
else
|
75
|
+
versions << data[gem_name].keys[choice.to_i - 1]
|
76
|
+
end
|
77
|
+
end
|
47
78
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
79
|
+
versions.each do |version|
|
80
|
+
gemdir = data[gem_name][version]
|
81
|
+
gemname = gem_name+'-'+version
|
82
|
+
gem_file = gemdir + '/gems/' + gemname
|
83
|
+
spec_file = gemdir + '/specifications/' + gemname + '.gemspec'
|
84
|
+
unless File.exists?("#{DIR}/gems/#{gemname}")
|
85
|
+
`ln -s #{gem_file} #{DIR}/gems/#{gemname} && ln -s #{spec_file} #{DIR}/specifications/#{gemname}.gemspec`
|
86
|
+
puts "Successfully symlinked #{gemname}"
|
87
|
+
else
|
88
|
+
puts "#{gemname} already exists"
|
89
|
+
end
|
90
|
+
|
91
|
+
# check dependencies
|
92
|
+
data = `gem dependency #{gem_name} -v #{version}`.chomp.split("\n")
|
93
|
+
data.shift
|
94
|
+
data.each do |dependency|
|
95
|
+
name = dependency.match(/\s+(.*?)\s\(/).captures[0]
|
96
|
+
if `gem query -i -n #{name}`.strip != 'true'
|
97
|
+
symlink([name])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
else
|
102
|
+
puts "Could not find gem #{gem_name}"
|
103
|
+
end
|
55
104
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
105
|
+
end
|
106
|
+
|
107
|
+
def method_missing(method, *args)
|
108
|
+
# must be a gem commands
|
109
|
+
system("gem --config-file #{DIR}/.gemrc #{method} #{args.join(' ')}")
|
59
110
|
end
|
60
111
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
112
|
+
end
|
113
|
+
|
114
|
+
args=ARGV
|
115
|
+
command=args.shift
|
116
|
+
Dispatch.send(command, args)
|
data/lib/templates/gemrc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
gempath:
|
2
|
-
- <%= @dir
|
3
|
-
gem: --no-rdoc --no-ri
|
4
|
-
|
2
|
+
- <%= @dir %>
|
3
|
+
<% unless @cfg['nodoc'] == false %>gem: --no-rdoc --no-ri<% end %>
|
4
|
+
sources:
|
5
5
|
- http://gems.rubyforge.org
|
6
6
|
- http://gems.github.com
|
7
|
+
<% (@cfg['sources'] || []).each do |source| %>- <%= source %>
|
8
|
+
<% end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toastyapps-gembox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Mongeau
|
@@ -12,7 +12,7 @@ cert_chain: []
|
|
12
12
|
date: 2009-03-18 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
description: Gembox allows you to create a sandbox for installing and using gems
|
15
|
+
description: Gembox allows you to create a sandbox for installing and using gems by way of an interactive shell.
|
16
16
|
email:
|
17
17
|
- halogenandtoast@gmail.com
|
18
18
|
executables:
|
@@ -61,6 +61,6 @@ rubyforge_project: gembox
|
|
61
61
|
rubygems_version: 1.2.0
|
62
62
|
signing_key:
|
63
63
|
specification_version: 2
|
64
|
-
summary: Gembox allows you to create a sandbox for installing and using gems
|
64
|
+
summary: Gembox allows you to create a sandbox for installing and using gems by way of an interactive shell.
|
65
65
|
test_files:
|
66
66
|
- test/test_gembox.rb
|