Class: Parser
- Inherits:
- 
      Object
      
        - Object
- Parser
 
- Defined in:
- lib/frozen_gems/parser.rb
Instance Method Summary collapse
- 
  
    
      #initialize(gemfile_path)  ⇒ Parser 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Parser. 
- #unfrozen_gems ⇒ Object
- #unfrozen_gems_hash ⇒ Object
Constructor Details
#initialize(gemfile_path) ⇒ Parser
Returns a new instance of Parser.
| 2 3 4 | # File 'lib/frozen_gems/parser.rb', line 2 def initialize(gemfile_path) @gemfile_path = gemfile_path end | 
Instance Method Details
#unfrozen_gems ⇒ Object
| 22 23 24 25 26 27 28 29 | # File 'lib/frozen_gems/parser.rb', line 22 def unfrozen_gems return [] unless gemfile? regex = /^\s*gem ['"]([-\w]+)['"](,.*)?/ gems = File.read(@gemfile_path).scan(regex).map do |g| g.first if g.last.nil? end gems.compact end | 
#unfrozen_gems_hash ⇒ Object
| 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # File 'lib/frozen_gems/parser.rb', line 6 def unfrozen_gems_hash return {} unless gemfile? hash = {} gems = unfrozen_gems regex = /(\w+(\-\w+)*)\s+\((\d+\.\d+\.\d+(\.\d+)*)\)/m gems_info = Dir.chdir(File.dirname(@gemfile_path)) do `bundle exec gem list`.scan(regex) end gems_info.each do |info| info.compact! name, version = info.first, info.last hash[name] = version if gems.include?(name) end hash end |