toastyapps-gembox 1.3.0 → 1.3.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.
Files changed (3) hide show
  1. data/lib/gembox.rb +38 -16
  2. data/lib/templates/bashrc +1 -1
  3. metadata +1 -1
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.0'
6
+ VERSION = '1.3.1'
7
7
  attr_accessor :dir, :cfg
8
8
  attr_accessor :cfg
9
9
 
@@ -13,29 +13,51 @@ class Gembox
13
13
  end
14
14
 
15
15
  def self.create(args)
16
+ box_name = args.shift
17
+ @dir = "#{ENV['HOME']}/.gembox/#{box_name}"
16
18
 
17
- dir = Dir.new(Dir.pwd+"/"+args.shift).path
18
- Dir.chdir(dir)
19
+ FileUtils.mkdir_p @dir # make gembox folder
20
+ FileUtils.mkdir_p "#{@dir}/usr/bin"
21
+ FileUtils.mkdir_p "#{@dir}/gems"
19
22
 
20
- @dir = dir = Dir.pwd
21
-
22
- FileUtils.mkdir_p "#{dir}/usr/bin"
23
- FileUtils.mkdir_p "#{dir}/gems"
24
-
25
- File.open("#{dir}/.gemrc", 'w') { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/gemrc").read).result(binding) }
26
- File.open("#{dir}/.bashrc", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/bashrc").read).result(binding) }
27
- File.open("#{dir}/shell.bash", "w") {|f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/shell.bash").read).result(binding) }
28
- File.open("#{dir}/dispatch.rb", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/dispatch.rb").read).result(binding) }
23
+ 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")
24
+ 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")
25
+ 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")
26
+ File.open("#{@dir}/dispatch.rb", "w") { |f| f.puts ERB.new(File.open(File.dirname(__FILE__)+"/templates/dispatch.rb").read).result(binding) } unless File.exists?("#{@dir}/dispatch.rb")
27
+ end
28
+
29
+ def self.list(args)
30
+ puts "Current Gem boxes:"
31
+ Dir.foreach("#{ENV['HOME']}/.gembox") do |file|
32
+ puts " - #{file}" if file !~ /^\./
33
+ end
34
+ end
35
+
36
+ def self.delete(args)
37
+ box_name = args.shift
38
+ @dir = "#{ENV['HOME']}/.gembox/#{box_name}"
39
+ if File.exists?(@dir)
40
+ FileUtils.rm_r(@dir)
41
+ puts "Gem box #{box_name} has been deleted"
42
+ else
43
+ puts "Gem box #{box_name} does not exists"
44
+ end
29
45
  end
30
46
 
31
47
  def self.shell(args)
32
- generate_gems_yaml
33
- system("sh shell.bash")
48
+ box_name = args.shift
49
+ @dir = "#{ENV['HOME']}/.gembox/#{box_name}"
50
+ if File.exists?(@dir)
51
+ generate_gems_yaml("#{@dir}/gems.yaml")
52
+ system("sh #{@dir}/shell.bash")
53
+ else
54
+ puts "Box #{box_name} does not exist"
55
+ end
34
56
  end
35
57
 
36
58
  private
37
59
 
38
- def self.generate_gems_yaml
60
+ def self.generate_gems_yaml(file)
39
61
  data = `gem query -d`.split("\n")
40
62
  gemdata = {}
41
63
  index = 'NULL'
@@ -61,7 +83,7 @@ class Gembox
61
83
  end
62
84
  end
63
85
  end
64
- File.open("gems.yaml", "w") { |f| f.puts gemdata.to_yaml }
86
+ File.open(file, "w") { |f| f.puts gemdata.to_yaml }
65
87
  end
66
88
 
67
89
  def load_config
data/lib/templates/bashrc CHANGED
@@ -4,4 +4,4 @@ alias gem='ruby <%= @dir %>/dispatch.rb'
4
4
  export GEM_PATH=<%= @dir %>/gems
5
5
  export GEM_HOME=<%= @dir %>/gems
6
6
 
7
- ruby dispatch.rb load_config
7
+ ruby <%= @dir %>/dispatch.rb load_config
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.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau