Class: RailGrinder::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rail_grinder/project.rb

Instance Method Summary collapse

Constructor Details

#initializeProject

Returns a new instance of Project.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rail_grinder/project.rb', line 5

def initialize
  @repos = []
  @repo_dir = RailGrinder::REPO_DIR
  @target_gem = nil
  @target_version = nil

  if Dir.exist?(@repo_dir)
    puts "Repositories will be cloned to the existing './#{@repo_dir}' directory."
  else
    Dir.mkdir @repo_dir
    # TODO: handle failure to create dir?
    puts "A new './#{@repo_dir}' directory has been created to clone repositories into."
  end
end

Instance Method Details

#add_repo(url) ⇒ Object

Add a git repository to the project.



21
22
23
# File 'lib/rail_grinder/project.rb', line 21

def add_repo(url)
  @repos = Repository.new(url, @repo_dir)
end

#save_stateObject



57
58
59
# File 'lib/rail_grinder/project.rb', line 57

def save_state
  open(RailGrinder::STATE_FILE, 'wb') { |f| f.puts Marshal.dump(self) }
end

#set_target(gem, version) ⇒ Object

Set the target gem that we want to update to the latest version in all the repositories in the project.



27
28
29
30
31
# File 'lib/rail_grinder/project.rb', line 27

def set_target(gem, version)
  # TODO: validate
  @target_gem = gem
  @target_version = version
end

#show_statusObject

Show the current status of all the repositories in the project. Show the version of the target gem, whether tests have passed or failed, whether the update has been committed, pushed, deployed, etc. in each repository.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rail_grinder/project.rb', line 37

def show_status
  # TODO: Iterate @repos instead?
  puts "You want '#{@target_gem}' at version #{@target_version}. Currently it's at:"
  proj_dir = Dir.pwd
  Dir.glob("#{@repo_dir}/*/Gemfile.lock").sort.each do |gemfile|
    app_dir = File.dirname(gemfile)
    Dir.chdir(File.join(proj_dir, app_dir))
    lockfile = Bundler::LockfileParser.new(
      Bundler.read_file(File.basename(gemfile))
    )

    lockfile.specs.each do |s|
      if s.name == @target_gem
        puts "#{s.version.to_s} : #{app_dir}"
        break
      end
    end
  end
end