Class: BundleManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo: raise, shell: raise) ⇒ BundleManager

Returns a new instance of BundleManager.



4
5
6
7
# File 'lib/bundle_manager.rb', line 4

def initialize(repo: raise, shell: raise)
  @shell = shell
  @repo = repo
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



2
3
4
# File 'lib/bundle_manager.rb', line 2

def repo
  @repo
end

#shellObject

Returns the value of attribute shell.



2
3
4
# File 'lib/bundle_manager.rb', line 2

def shell
  @shell
end

Instance Method Details

#bundle(gemfile_directory) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/bundle_manager.rb', line 17

def bundle(gemfile_directory)
  begin
    shell.run "bundle install --local", dir: gemfile_directory
  rescue ShellRunner::CommandFailureError
    puts 'trying without --local'
    shell.run "bundle install", dir: gemfile_directory
  end
end

#bundle_where_necessaryObject



9
10
11
12
13
14
15
# File 'lib/bundle_manager.rb', line 9

def bundle_where_necessary
  find("Gemfile.lock").each do |gemfile_lock|
    if repo.changed?(gemfile_lock)
      bundle(directory_of(gemfile_lock))
    end
  end
end

#directory_of(file_path) ⇒ Object



30
31
32
# File 'lib/bundle_manager.rb', line 30

def directory_of(file_path)
  File.dirname(file_path)
end

#find(file_name) ⇒ Object



26
27
28
# File 'lib/bundle_manager.rb', line 26

def find(file_name)
  Dir.glob("**/#{file_name}")
end