Module: Bundlegem
- Defined in:
- lib/bundlegem.rb,
lib/bundlegem/cli.rb,
lib/bundlegem/cli/gem.rb,
lib/bundlegem/strings.rb,
lib/bundlegem/version.rb,
lib/bundlegem/configurator.rb,
lib/bundlegem/friendly_errors.rb,
lib/bundlegem/template_manager.rb
Defined Under Namespace
Classes: CLI, Configurator, TemplateManager
Constant Summary
collapse
- HELP_MSG =
" BundleGem version \#{Bundlegem::VERSION}\nUse bundlegem to start a new project folder based on a predefined template.\n\nUsage Examples:\n\n# Make a new ruby gem\n$ bundlegem your_gem_name\n\n# List available teplates\n$ bundlegem --list\n\n# Create a ruby gem project using the built in service template\n$ bundlegem your_gem_name -t service\n\n# Download all my template files (configured in ~/.bundlegem/config)\n$ bundlegem --install-best-templates\n\n# not implemented, should create a new gem template in ~/.bundlegem/templates\n# that you'll love customizing to your personal preference\n$ bundlegem --newtemplate\n\n$ bundlegem --help # shows this message\n"
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.convert_grouped_hashes_to_output(available_templates) ⇒ Object
input: [ { “predefined” => [“default”, “service”] },
{ "MISC" => ["my_thing"] }
]
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/bundlegem.rb', line 99
def convert_grouped_hashes_to_output(available_templates)
s = ""
available_templates.each do |hash|
k = hash.first.upcase
a = hash.last
s << " #{k}:\n"
a.each do |el|
s << " #{el}\n"
end
s << "\n"
end
s
end
|
.gem(options, gem_name) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/bundlegem.rb', line 56
def gem(options, gem_name)
require 'bundlegem/cli'
require 'bundlegem/cli/gem'
Bundlegem::CLI::Gem.new(options, gem_name).run
end
|
.group_hashes_by_key(available_templates) ⇒ Object
input: [ { “predefined” => “default” },
{ "MISC" => "my_thing" },
{ "prdefined" => "service" }
]
output: [ { “predefined” => [“default”, “service”] },
{ "MISC" => ["my_thing"] }
]
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/bundlegem.rb', line 85
def group_hashes_by_key(available_templates)
h = {}
available_templates.each do |hash|
k = hash.first.first
v = hash.first.last
h[k] = [] unless h.has_key?(k)
h[k] << v
end
h
end
|
.install_best_templates ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/bundlegem.rb', line 38
def install_best_templates
configurator = Configurator.new
config_file_data = configurator.config_file_data
puts "Downloading templates from the following locations: \n #{config_file_data['best_templates'].split(" ").join("\n ")}"
config_file_data['best_templates'].split.each do |url|
uri = URI.parse(url)
template_folder_name = File.basename(uri.path).sub(/\.git$/, "")
if !File.exist?("#{ENV['HOME']}/.bundlegem/templates/#{template_folder_name}")
cmd = "cd #{ENV['HOME']}/.bundlegem/templates && git clone #{url}"
cmd += " 2> /dev/null" if $test_env
`#{cmd}`
else
end
end
end
|
.issues_url(exception) ⇒ Object
74
75
76
77
|
# File 'lib/bundlegem/friendly_errors.rb', line 74
def self.issues_url(exception)
'TODO: Change the link that was here' \
"#{CGI.escape(exception.message)}&type=Issues"
end
|
.list ⇒ Object
lists available templates
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/bundlegem.rb', line 19
def list
configurator = Configurator.new
available_templates = [ { "predefined" => "newgem" },
{ "predefined" => "c_extension_gem" },
{ "predefined" => "cli_gem" }]
available_templates += configurator.user_downloaded_templates
available_templates += configurator.user_defined_templates
available_templates = group_hashes_by_key(available_templates)
output_string = convert_grouped_hashes_to_output(available_templates)
mark_default_template(output_string, configurator.default_template)
end
|
.mark_default_template(output_string, default_template) ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/bundlegem.rb', line 113
def mark_default_template(output_string, default_template)
output_string.lines.reverse.map do |l|
if l.strip == default_template
l[1]= "*"
"#{l.chomp} (default)\n"
else
l
end
end.reverse.join
end
|
.new_template(args) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/bundlegem.rb', line 63
def new_template(args)
template_name = args[1]
template_name = prompt_for_template_name if template_name.nil?
TemplateManager.create_new_template(template_name)
end
|
.prompt_for_template_name ⇒ Object
71
72
73
74
|
# File 'lib/bundlegem.rb', line 71
def prompt_for_template_name
puts "Please specify a name for your template: "
template_name = STDIN.gets.chomp.strip.gsub(" ", "_")
end
|
.request_issue_report_for(e) ⇒ Object
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
|
# File 'lib/bundlegem/friendly_errors.rb', line 45
def self.request_issue_report_for(e)
Bundlegem.ui.info " \#{'\u2015\u2015\u2015 ERROR REPORT TEMPLATE \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015'}\n - What did you do?\n - What did you expect to happen?\n - What happened instead?\n\n Error details\n\n \#{e.class}: \#{e.message}\n \#{e.backtrace.join(\"\\n \")}\n\n \#{Bundlegem::Env.new.report(:print_gemfile => false).gsub(/\\n/, \"\\n \").strip}\n \#{'\u2015\u2015\u2015 TEMPLATE END \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015'}\n\n EOS\n\n Bundlegem.ui.error \"Unfortunately, an unexpected error occurred, and Bundlegem cannot continue.\"\n\n Bundlegem.ui.warn <<-EOS.gsub(/^ {6}/, '')\n\n First, try this link to see if there are any existing issue reports for this error:\n \#{issues_url(e)}\n\n If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:\n TODO: Change the link that was here\n EOS\nend\n".gsub(/^ {6}/, '')
|
.version ⇒ Object
14
15
16
|
# File 'lib/bundlegem.rb', line 14
def version
Bundlegem::VERSION
end
|
.which(executable) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/bundlegem.rb', line 124
def which(executable)
if File.file?(executable) && File.executable?(executable)
executable
elsif ENV['PATH']
path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
abs_path = File.join(p, executable)
File.file?(abs_path) && File.executable?(abs_path)
end
path && File.expand_path(executable, path)
end
end
|
.with_friendly_errors ⇒ Object
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
|
# File 'lib/bundlegem/friendly_errors.rb', line 6
def self.with_friendly_errors
yield
rescue Bundlegem::Dsl::DSLError => e
Bundlegem.ui.error e.message
exit e.status_code
rescue Bundlegem::BundlegemError => e
Bundlegem.ui.error e.message, :wrap => true
Bundlegem.ui.trace e
exit e.status_code
rescue Thor::AmbiguousTaskError => e
Bundlegem.ui.error e.message
exit 15
rescue Thor::UndefinedTaskError => e
Bundlegem.ui.error e.message
exit 15
rescue Thor::Error => e
Bundlegem.ui.error e.message
exit 1
rescue LoadError => e
raise e unless e.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/
Bundlegem.ui.error "\nCould not load OpenSSL."
Bundlegem.ui.warn " You must recompile Ruby with OpenSSL support or change the sources in your \\\n Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL \\\n using RVM are available at http://rvm.io/packages/openssl.\n WARN\n Bundlegem.ui.trace e\n exit 1\nrescue Interrupt => e\n Bundlegem.ui.error \"\\nQuitting...\"\n Bundlegem.ui.trace e\n exit 1\nrescue SystemExit => e\n exit e.status\nrescue Exception => e\n request_issue_report_for(e)\n exit 1\nend\n", :wrap => true
|