module Bundlegem

Constants

HELP_MSG
VERSION

Public Class Methods

convert_grouped_hashes_to_output(available_templates) click to toggle source

input: [ { “predefined” => [“default”, “service”] },

  { "MISC" => ["my_thing"] }
]
# 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) click to toggle source
# 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) click to toggle source

input: [ { “predefined” => “default” },

  { "MISC" => "my_thing" },
  { "prdefined" => "service" }
]

output: [ { “predefined” => [“default”, “service”] },

  { "MISC" => ["my_thing"] }
]
# 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() click to toggle source
# 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.exists?("#{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
      # TODO:
      # Prompt to update the repo if they have a clean working state.
    end
  end
end
issues_url(exception) click to toggle source
# 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() click to toggle source

lists available templates

# File lib/bundlegem.rb, line 19
def list
  configurator = Configurator.new
  # search through builtin
  available_templates = [ { "predefined" => "newgem" },
                          { "predefined" => "c_extension_gem" },
                          { "predefined" => "cli_gem" }]

  # search through user downloaded
  available_templates += configurator.user_downloaded_templates

  # search through user defined
  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) click to toggle source
# 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) click to toggle source
# File lib/bundlegem.rb, line 63
def new_template(args)
  template_name = args[1]
  template_name = prompt_for_template_name if template_name.nil?

  # Copy newgem from within the repo to ~/.bundlegem/templates/#{template_name}
  TemplateManager.create_new_template(template_name)
end
prompt_for_template_name() click to toggle source
# 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) click to toggle source
# File lib/bundlegem/friendly_errors.rb, line 45
  def self.request_issue_report_for(e)
    Bundlegem.ui.info <<-EOS.gsub(/^ {6}/, '')
      #{'――― ERROR REPORT TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――'}
      - What did you do?
      - What did you expect to happen?
      - What happened instead?

      Error details

          #{e.class}: #{e.message}
          #{e.backtrace.join("\n          ")}

      #{Bundlegem::Env.new.report(:print_gemfile => false).gsub(/\n/, "\n      ").strip}
      #{'――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'}

    EOS

    Bundlegem.ui.error "Unfortunately, an unexpected error occurred, and Bundlegem cannot continue."

    Bundlegem.ui.warn <<-EOS.gsub(/^ {6}/, '')

      First, try this link to see if there are any existing issue reports for this error:
      #{issues_url(e)}

      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:
      TODO: Change the link that was here
    EOS
  end
version() click to toggle source
# File lib/bundlegem.rb, line 14
def version
  Bundlegem::VERSION
end
which(executable) click to toggle source
# 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() { || ... } click to toggle source
# 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 <<-WARN, :wrap => true
      You must recompile Ruby with OpenSSL support or change the sources in your \
      Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL \
      using RVM are available at http://rvm.io/packages/openssl.
    WARN
    Bundlegem.ui.trace e
    exit 1
  rescue Interrupt => e
    Bundlegem.ui.error "\nQuitting..."
    Bundlegem.ui.trace e
    exit 1
  rescue SystemExit => e
    exit e.status
  rescue Exception => e
    request_issue_report_for(e)
    exit 1
  end