Class: Lapidario::LockfileInfo
- Inherits:
-
Object
- Object
- Lapidario::LockfileInfo
- Defined in:
- lib/lockfile_info.rb
Instance Attribute Summary collapse
-
#git_gems ⇒ Object
Returns the value of attribute git_gems.
-
#primary_gems ⇒ Object
Returns the value of attribute primary_gems.
-
#rubygems_gems ⇒ Object
Returns the value of attribute rubygems_gems.
Class Method Summary collapse
-
.get_git_gems_from_gemfile_lock(gemfile_lock_as_strings) ⇒ Object
gets gems under GIT namespace.
-
.get_rubygems_from_gemfile_lock(gemfile_lock_as_strings) ⇒ Object
gets gems installed from rubygems; in the future check also for other remote sources.
Instance Method Summary collapse
- #git_gems? ⇒ Boolean
-
#initialize(gemfile_lock_as_strings, include_git = true) ⇒ LockfileInfo
constructor
A new instance of LockfileInfo.
- #puts_versionless_rubygems_info ⇒ Object
Constructor Details
#initialize(gemfile_lock_as_strings, include_git = true) ⇒ LockfileInfo
Returns a new instance of LockfileInfo.
9 10 11 12 13 14 15 |
# File 'lib/lockfile_info.rb', line 9 def initialize(gemfile_lock_as_strings, include_git = true) @git_gems = Lapidario::LockfileInfo.get_git_gems_from_gemfile_lock(gemfile_lock_as_strings) if include_git @git_gems ||= {} @rubygems_gems = Lapidario::LockfileInfo.get_rubygems_from_gemfile_lock(gemfile_lock_as_strings) # joins gem names and versions from git/rubygems/other sources in a single format @primary_gems = @git_gems.merge(@rubygems_gems) end |
Instance Attribute Details
#git_gems ⇒ Object
Returns the value of attribute git_gems.
7 8 9 |
# File 'lib/lockfile_info.rb', line 7 def git_gems @git_gems end |
#primary_gems ⇒ Object
Returns the value of attribute primary_gems.
7 8 9 |
# File 'lib/lockfile_info.rb', line 7 def primary_gems @primary_gems end |
#rubygems_gems ⇒ Object
Returns the value of attribute rubygems_gems.
7 8 9 |
# File 'lib/lockfile_info.rb', line 7 def rubygems_gems @rubygems_gems end |
Class Method Details
.get_git_gems_from_gemfile_lock(gemfile_lock_as_strings) ⇒ Object
gets gems under GIT namespace
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lockfile_info.rb', line 53 def self.get_git_gems_from_gemfile_lock(gemfile_lock_as_strings) git_gem_sections = [] gem_names_and_versions = {} gemfile_lock_as_strings.each_with_index do |line, index| git_gem_sections << Helper.slice_up_to_next_empty_line(index, gemfile_lock_as_strings) if line == "GIT" end return [] if git_gem_sections.empty? git_gem_sections.each do |git_gem| git_gem_info = Lapidario::Helper.extract_git_gem_info git_gem name = git_gem_info[0] version_and_remote = git_gem_info[1] gem_names_and_versions[name] = version_and_remote end gem_names_and_versions end |
.get_rubygems_from_gemfile_lock(gemfile_lock_as_strings) ⇒ Object
gets gems installed from rubygems; in the future check also for other remote sources
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lockfile_info.rb', line 30 def self.get_rubygems_from_gemfile_lock(gemfile_lock_as_strings) gem_section = [] gem_names_and_versions = {} gemfile_lock_as_strings.each_with_index do |line, index| gem_section = Helper.slice_up_to_next_empty_line(index, gemfile_lock_as_strings) if line == "GEM" end if gem_section.empty? raise "#{gemfile_lock_as_strings.join("\n")}\n\nEND OF OUTPUT\nA line consisting of a single 'GEM' string with no further chars wasn't found. See output above." end gem_section.each do |line| next unless Lapidario::Helper.lockfile_primary_gem_line? line gem_name_and_version = line.clone.strip.split(" ") name = gem_name_and_version[0] version = gem_name_and_version[1] gem_names_and_versions[name] = version ? version.gsub(/[()]/, "") : "" end gem_names_and_versions end |
Instance Method Details
#git_gems? ⇒ Boolean
25 26 27 |
# File 'lib/lockfile_info.rb', line 25 def git_gems? @git_gems && !@git_gems.empty? end |
#puts_versionless_rubygems_info ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/lockfile_info.rb', line 17 def puts_versionless_rubygems_info versionless_gems = [] @rubygems_gems.each do |gem, version| versionless_gems << [gem, version] if version.nil? || version.empty? end print "#{versionless_gems.join("\n")}\nThere are #{versionless_gems.size} gems without specified version, names are listed above." end |