Module: Breezer

Defined in:
lib/breezer.rb,
lib/breezer/parser.rb,
lib/breezer/command.rb,
lib/breezer/freezer.rb,
lib/breezer/version.rb

Overview

This is our main class. Call Breezer.freeze! to update the Gemfile

Defined Under Namespace

Classes: Command, Freezer, Parser

Constant Summary collapse

VERSION =
'0.10.0'

Class Method Summary collapse

Class Method Details

.check_gemfile!(gemfile, deps, options) ⇒ Object



24
25
26
27
28
29
# File 'lib/breezer.rb', line 24

def self.check_gemfile!(gemfile, deps, options)
  puts "Checking Gemfile #{gemfile}..."
  checks = Freezer.check_gemfile!(gemfile, deps, options)
  print_check_results(checks)
  checks.values.map { |e| e[:valid] }.all?
end

.freeze!(gemfile_path, lockfile_path, **options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/breezer.rb', line 8

def self.freeze!(gemfile_path, lockfile_path, **options)
  puts "Updating Gemfile #{gemfile_path}..."
  absolute_lockfile_path = File.join(lockfile_path)
  absolute_gemfile_path = File.join(gemfile_path)
  ENV['BUNDLE_GEMFILE'] = absolute_gemfile_path

  deps = Parser.deps(absolute_lockfile_path, options)

  gemfile = Bundler.read_file(absolute_gemfile_path)
  if options[:check]
    check_gemfile!(gemfile, deps, options)
  else
    update_gemfile!(gemfile, deps, options, options[:output] || absolute_gemfile_path)
  end
end


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/breezer.rb', line 48

def self.print_check_results(checks)
  invalid = checks.reject { |_k, v| v[:valid] }
  if invalid.empty?
    (puts 'Gemfile dependencies are properly constrained' && return)
  end
  puts "#{invalid.values.count} dependencies are not properly set"
  invalid.each do |no, line|
    suggested = line[:proposed_version] ? " (Suggested: '~> #{line[:proposed_version]}')" : ''
    puts format('Line %-3d: gem %-20s%s', no, "'#{line[:name]}'", suggested)
  end
end

.update_gemfile!(gemfile, deps, options, output) ⇒ Object



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

def self.update_gemfile!(gemfile, deps, options, output)
  updated_gemfile = Freezer.update_gemfile!(gemfile, deps, options)
  write_or_print_output(updated_gemfile, output, options)
end

.write_or_print_output(updated_gemfile, output_path, **options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/breezer.rb', line 36

def self.write_or_print_output(updated_gemfile, output_path, **options)
  if options[:dry]
    puts updated_gemfile
  else
    File.open(output_path, 'w') do |file|
      file.write(updated_gemfile)
    end
    puts 'Gemfile updated !'
  end
  updated_gemfile
end