toastyapps-gembox 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,15 @@ require 'yaml'
3
3
  require 'erb'
4
4
 
5
5
  class Gembox
6
- VERSION = '1.1.2'
7
- attr_accessor :dir
6
+ VERSION = '1.2.0'
7
+ attr_accessor :dir, :cfg
8
+ attr_accessor :cfg
9
+
10
+ def initialize
11
+ @cfg_path = `cd ~/ && pwd`.chomp + "/.gemboxrc"
12
+ load_config
13
+ end
14
+
8
15
  def self.create(args)
9
16
 
10
17
  dir = Dir.new(Dir.pwd+"/"+args.shift).path
@@ -23,13 +30,12 @@ class Gembox
23
30
 
24
31
  def self.shell(args)
25
32
  generate_gems_yaml
26
-
27
33
  system("sh shell.bash")
28
34
  end
29
35
 
30
36
  private
31
37
 
32
- def generate_gems_yaml
38
+ def self.generate_gems_yaml
33
39
  data = `gem query -d`.split("\n")
34
40
  gemdata = {}
35
41
  index = 'NULL'
@@ -56,6 +62,13 @@ class Gembox
56
62
  end
57
63
  end
58
64
  File.open("gems.yaml", "w") { |f| f.puts gemdata.to_yaml }
65
+
66
+ def load_config
67
+ @cfg = load_yaml(@cfg_path)
68
+ end
69
+
70
+ def load_yaml path
71
+ File.exists?(path) ? YAML.load(File.open(path)) : nil
59
72
  end
60
73
 
61
74
  end
@@ -13,17 +13,38 @@ when 'query'
13
13
  when 'symlink'
14
14
  data = YAML.load(File.open('<%= @dir %>/gems.yaml').read)
15
15
  gem_name = args.shift
16
- if data[gem_name].keys.length == 1
16
+ if data[gem_name] && data[gem_name].keys.length > 0
17
17
  FileUtils.mkdir_p('<%= @dir %>/gems/gems/')
18
18
  FileUtils.mkdir_p('<%= @dir %>/gems/specifications/')
19
- version = data[gem_name].keys[0]
20
- gemdir = data[gem_name][version]
21
- gemname = gem_name+'-'+version
22
- gem_file = gemdir + '/gems/' + gemname
23
- spec_file = gemdir + '/specifications/' + gemname + '.gemspec'
24
- `ln -s #{gem_file} <%= @dir %>/gems/gems/#{gemname} && ln -s #{spec_file} <%= @dir %>/gems/specifications/#{gemname}.gemspec`
25
- elsif data[gem_name].keys.length > 1
26
- puts 'This gem has multiple versions. Gembox does not supporting gems with multiple versions installed yet.'
19
+ versions = []
20
+ if data[gem_name].keys.length == 1
21
+ versions << data[gem_name].keys[0]
22
+ elsif data[gem_name].keys.length > 1
23
+ puts 'Select gem to symlink:'
24
+ index = 1
25
+ data[gem_name].keys.each do |key|
26
+ puts " #{index}. #{gem_name}-#{key}"
27
+ index += 1
28
+ end
29
+ puts " #{index}. All versions"
30
+ print "> "
31
+ choice = gets
32
+ if choice == index
33
+ versions = data[gem_name].keys
34
+ else
35
+ versions << data[gem_name].keys[choice.to_i - 1]
36
+ end
37
+ end
38
+
39
+ versions.each do |version|
40
+ gemdir = data[gem_name][version]
41
+ gemname = gem_name+'-'+version
42
+ gem_file = gemdir + '/gems/' + gemname
43
+ spec_file = gemdir + '/specifications/' + gemname + '.gemspec'
44
+ `ln -s #{gem_file} <%= @dir %>/gems/gems/#{gemname} && ln -s #{spec_file} <%= @dir %>/gems/specifications/#{gemname}.gemspec`
45
+ puts "Successfully symlinked #{gemname}"
46
+ end
47
+
27
48
  else
28
49
  puts "Could not find gem #{gem_name}"
29
50
  end
@@ -1,8 +1,27 @@
1
- require "test/unit"
2
- require "gembox"
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/gembox")
3
4
 
4
- class TestGembox < Test::Unit::TestCase
5
- def test_sanity
6
- flunk "write tests or I will kneecap you"
5
+ describe Gembox do
6
+ before(:each) do
7
+ @gb = Gembox.new
8
+ @cfg_file_path = File.expand_path(File.dirname(__FILE__)) + '/sample.gemboxrc.yml'
7
9
  end
8
- end
10
+
11
+ it "should load the current users config file" do
12
+ cfg = @gb.load_yaml @cfg_file_path
13
+ cfg.should_not be_nil
14
+ end
15
+
16
+ it "should skip config file if not found" do
17
+ cfg = @gb.load_yaml "~/some/random/path"
18
+ cfg.should be_nil
19
+ end
20
+
21
+ it "should find .gemboxrc" do
22
+ home = `cd ~/ && pwd`.chomp
23
+ cfg = @gb.load_yaml "#{home}/.gemboxrc"
24
+ cfg.should_not be_nil
25
+ end
26
+
27
+ 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.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau