module RailGrinder

require 'rugged'

Constants

REPO_DIR
STATE_FILE
VERSION

Public Class Methods

inferred_name(url) click to toggle source

Get the base name of the repository from its url. Module method rather than private class method so it makes a nice testable unit.

# File lib/rail_grinder/repository.rb, line 5
def RailGrinder.inferred_name(url)
  # Get the bit of the url after the last /
  name = if url =~ %r|/([^/]+)$|
           Regexp.last_match[1]
         end
  name.gsub!(/\.git$/, '')
  unless name
    raise "Couldn't guess name of app from the repo url"
  end
  name
end
run() click to toggle source
# File lib/rail_grinder.rb, line 19
def RailGrinder.run
  # If there is saved project state, load it.
  # Otherwise create a new project.
  project = if File.exist?(STATE_FILE)
              Marshal.load( File.read(STATE_FILE) )
            else
              Project.new
            end

  # Drop the user in a prompt and process commands as they are entered
  prompt = 'rg> '
  while line = Readline.readline(prompt, true)
    args = line.split
    command = args.shift

    case command
    when 'add'
      # rg> add git@gitlab.com:lycoperdon/foo.git
      project.add_repo(args.shift)
    when 'target'
      # rg> target rails 4.2.7
      (target_gem, target_version) = *args
      project.set_target(target_gem, target_version)
      prompt = "rg #{target_gem}@#{target_version}> "
    when 'status'
      project.show_status
    when 'help'
      RailGrinder.show_help
    when /exit|quit/
      project.save_state
      puts "Goodbye..."
      break
    else
      puts "I'm sorry, I don't know about that command"
      RailGrinder.show_help
    end
  end

  # TODO:
  # Clean out after testing...
  # `rm -rf repos/{*,.*}
end
show_help() click to toggle source
# File lib/rail_grinder.rb, line 15
def RailGrinder.show_help
  puts "TODO: Actually put the help here"
end