toastyapps-gembox 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/gembox.rb +56 -1
  2. metadata +1 -1
data/lib/gembox.rb CHANGED
@@ -1,5 +1,8 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+
1
4
  class Gembox
2
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
3
6
 
4
7
  def self.create(args)
5
8
  dir = Dir.new(Dir.pwd+"/"+args.shift).path
@@ -23,11 +26,34 @@ class Gembox
23
26
  end
24
27
  File.open("#{dir}/dispatch.rb", "w") do |f|
25
28
  f.puts "#!/usr/bin/ruby"
29
+ f.puts "require 'rubygems'"
30
+ f.puts "require 'yaml'"
31
+ f.puts "require 'fileutils'"
26
32
  f.puts "args=ARGV"
27
33
  f.puts "command=args.shift"
28
34
  f.puts "case command"
29
35
  f.puts "when 'install'"
30
36
  f.puts " system(\"gem --config-file #{dir}/.gemrc #\{command\} --bindir #{dir}/usr/bin #\{ARGV.join(' ')\}\")"
37
+ f.puts "when 'query'"
38
+ f.puts " puts 'here'"
39
+ f.puts " system(\"gem query #\{ARGV.join(' ')\}\")"
40
+ f.puts "when 'symlink'"
41
+ f.puts " data = YAML.load(File.open('#{dir}/gems.yaml').read)"
42
+ f.puts " gem_name = args.shift"
43
+ f.puts " if data[gem_name].keys.length == 1"
44
+ f.puts " FileUtils.mkdir_p('#{dir}/gems/gems/')"
45
+ f.puts " FileUtils.mkdir_p('#{dir}/gems/specifications/')"
46
+ f.puts " version = data[gem_name].keys[0]"
47
+ f.puts " gemdir = data[gem_name][version]"
48
+ f.puts " gemname = gem_name+'-'+version"
49
+ f.puts " gem_file = gemdir + '/gems/' + gemname"
50
+ f.puts " spec_file = gemdir + '/specifications/' + gemname + '.gemspec'"
51
+ f.puts " \`ln -s #\{gem_file\} #{dir}/gems/gems/#\{gemname\} && ln -s #\{spec_file\} #{dir}/gems/specifications/#\{gemname\}.gemspec\`"
52
+ f.puts " elsif data[gem_name].keys.length > 1"
53
+ f.puts " puts 'This gem has multiple versions. Gembox does not supporting gems with multiple versions installed yet.'"
54
+ f.puts " else"
55
+ f.puts " puts \"Could not find gem #\{gem_name\}\""
56
+ f.puts " end"
31
57
  f.puts "else"
32
58
  f.puts " system(\"gem --config-file #{dir}/.gemrc #\{command\} #\{ARGV.join(' ')\}\")"
33
59
  f.puts "end"
@@ -35,6 +61,35 @@ class Gembox
35
61
  end
36
62
 
37
63
  def self.shell(args)
64
+ data = `gem query -d`.split("\n")
65
+ gemdata = {}
66
+ index = 'NULL'
67
+ in_installed_at = false
68
+ data.each do |line|
69
+ if line =~ /^[a-z]/i
70
+ index = line.split(' ')[0]
71
+ versions = line.match(/\((.*?)\)/).captures[0].split(', ')
72
+ gemdata[index] = {}
73
+ versions.each do |version|
74
+ gemdata[index][version] = ''
75
+ end
76
+ elsif line =~ /Installed at/ || in_installed_at
77
+ if line.match(/\((.*?)\):\s(.*)/)
78
+ in_installed_at = true
79
+ version, dir = line.match(/\((.*?)\):\s(.*)/).captures
80
+ gemdata[index][version] = dir
81
+ elsif line =~ /Installed at/
82
+ dir = line.match(/:\s(.*)/).captures[0]
83
+ gemdata[index][gemdata[index].keys[0]] = dir
84
+ else
85
+ in_installed_at = false
86
+ end
87
+ end
88
+ end
89
+ File.open("gems.yaml", "w") do |f|
90
+ f.puts gemdata.to_yaml
91
+ end
38
92
  system("sh shell.bash")
39
93
  end
94
+
40
95
  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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau