-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgem_handler.rb
More file actions
86 lines (68 loc) · 1.67 KB
/
Copy pathgem_handler.rb
File metadata and controls
86 lines (68 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require 'open3'
def installGem(gem_name,options,app_name)
file_path = Dir.pwd+"/Recipes/"+gem_name+".rb"
if(!File.file?(file_path))
puts "Sorry, "+gem_name+" is not supported"
exit
end
File.open(Dir.pwd+"/"+app_name+"/Gemfile").each do |line|
if line.include?(gem_name)
puts gem_name+" already installed"
exit
end
end
content = []
File.open(file_path).each do |line|
content << line
end
keywords = ["system","homepage","category","version","def","end"]
parsed_recipe = parseRecipe(content,keywords)
# adding gem to gemfile
File.open(Dir.pwd+"/"+app_name+"/Gemfile","a") do |file|
file.puts "#gem added by X"
string = "gem \"#{gem_name}\""
unless parsed_recipe["version"].nil?
string += ", #{parsed_recipe["version"]}"
end
file.puts string
end
puts "Installing "+gem_name+" "+parsed_recipe["version"]+"..."
puts "More info: "+parsed_recipe["homepage"]
Dir.chdir app_name do
parsed_recipe["system"].each do |element|
if element["only"].nil?
executeCommand(element["command"])
elsif options.include? (element["only"])
executeCommand(element["command"])
end
end
end
end
# suggested gem for each category, hard coded seems the way to go
def chooseGem(category)
case category
when "Authentication"
"devise"
when "Testing"
"cucumber"
when "Layout"
"bootstrap"
else
puts "Category "+category+" doesn't exist"
exit
end
end
def executeCommand(command)
p command.rstrip.lstrip.gsub(/"/,'')
Open3.popen3(command.rstrip.lstrip.gsub(/\"/,'')) {|stdin, stdout, stderr, wait_thr|
stdout.each do |line|
p line
end
if(wait_thr.value.exitstatus != 0)
stderr.each do |line|
p line
end
exit
end
}
end