Class: BundleLock::Searcher

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

Defined Under Namespace

Classes: GemfileNotFound

Instance Method Summary collapse

Instance Method Details

#all_gemsObject



106
107
108
109
110
# File 'lib/bundle_lock/searcher.rb', line 106

def all_gems
  @all_gems ||= gemfile.grep(/^\s*.+\s\((?![~><=]).+?\)$/).collect do |gem|
    GemDependency.new gem.strip()
  end
end

#current_gemsObject



86
87
88
# File 'lib/bundle_lock/searcher.rb', line 86

def current_gems
  @current_gems ||= all_gems.find_all()
end

#gemfileObject



98
99
100
101
102
103
104
# File 'lib/bundle_lock/searcher.rb', line 98

def gemfile
  unless File.exists?('Gemfile.lock')
    raise GemfileNotFound, 'Gemfile.lock not found! Please re-run in your Ruby project directory.'
  end

  @gemfile ||= File.read('Gemfile.lock').split(/\n/)
end

#handwaving_gemsObject



94
95
96
# File 'lib/bundle_lock/searcher.rb', line 94

def handwaving_gems
  @handwaving_gems ||= all_gems.find_all(&:handwaving?)
end

#outdated_gemsObject



90
91
92
# File 'lib/bundle_lock/searcher.rb', line 90

def outdated_gems
  @outdated_gems ||= all_gems.find_all(&:outdated?)
end

#search!(version = 'all', type = 'all') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bundle_lock/searcher.rb', line 5

def search!(version='all',type='all')
  puts "Finding current and outdated gems.."

  unless version == 'new'
    puts "#"*80
    puts "# To Lock Current gem versions in Gemfile: "
    puts "#"*80 
    current_gems.each do |gem|
      puts "  gem '#{gem.name}', '#{gem.version}'"
    end
    puts "#"*80
    puts
    
    unless type == 'gemfile'
      puts "#"*80
      puts "# To Lock Current gem versions for Maven by putting the following in your pom.xml: "
      puts "#"*80
      puts "The following assumes you already use Maven for Gem Dependencies *"
      puts
      xml = Builder::XmlMarkup.new(:target => $stdout, :indent => 2)
      current_gems.each do |gem|
      xml.dependency {
        xml.groupId "rubygems"
        xml.artifactId "#{gem.name}"
        xml.version "#{gem.version}"
        xml.type "gem"
      }
      end
      puts
      puts "*: JRuby Maven Info: https://github.com/mkristian/jruby-maven-plugins/"
      puts "#"*80
    end
    puts
  end
  
  unless outdated_gems.empty? or version == 'current'
    puts "#"*80
    puts "# To Update and Lock New Gems: "
    puts "#"*80
    puts "\nNewer versions found for:"
    outdated_gems.each do |gem|
      puts "  #{gem.name} (#{gem.latest_version} > #{gem.version})"
    end

    puts "\nLock bundle to NEW gem versions by putting the following in your Gemfile:"
    outdated_gems.each do |gem|
      puts "  gem '#{gem.name}', '#{gem.latest_version}'"
    end
    puts "#"*80
    
    unless type == 'gemfile'
      puts "#"*80
      puts "# To Lock NEW gems versions for Maven by putting the following in your pom.xml: "
      puts "#"*80
      puts "The following assumes you already use Maven for Gem Dependencies *"
      puts
      xml = Builder::XmlMarkup.new(:target => $stdout, :indent => 2)
      outdated_gems.each do |gem|
      xml.dependency {
        xml.groupId "rubygems"
        xml.artifactId "#{gem.name}"
        xml.version "#{gem.version}"
        xml.type "gem"
      }
      end
      puts
      puts "*: JRuby Maven Info: https://github.com/mkristian/jruby-maven-plugins/"
      puts "#"*80
    end
  end

  unless handwaving_gems.empty?
    puts "\nYou may try to update non-specific dependencies via:"
    puts "  $ bundle update #{handwaving_gems.collect(&:name).join(' ')}"
    puts "\nHandwaving specifications:"
    handwaving_gems.collect do |g|
      puts "  #{g.name}: #{ [ g.handwaving, g.version ].join(' ') }"
     end
  end
end