Module: RailGrinder

Defined in:
lib/rail_grinder.rb,
lib/rail_grinder/project.rb,
lib/rail_grinder/version.rb,
lib/rail_grinder/repository.rb

Overview

require ‘rugged’

Defined Under Namespace

Classes: Project, Repository

Constant Summary collapse

REPO_DIR =
'repos'
STATE_FILE =
'.rail_grinder'
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.inferred_name(url) ⇒ Object

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



5
6
7
8
9
10
11
12
13
14
15
# 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

.runObject



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
# 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 [email protected]: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_helpObject



15
16
17
# File 'lib/rail_grinder.rb', line 15

def RailGrinder.show_help
  puts "TODO: Actually put the help here"
end