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



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

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
16
# File 'lib/bundle_manager.rb', line 9

def bundle_where_necessary
  shell.notify "\nBundling:"
  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



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

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

#find(file_name) ⇒ Object



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

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