Class: GemsStatus::LockfileGems
- Inherits:
-
Object
- Object
- GemsStatus::LockfileGems
- Defined in:
- lib/gems-status/sources/lockfile_gems.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #gem_list ⇒ Object
- #get_data(dirname, filename) ⇒ Object
-
#initialize(conf) ⇒ LockfileGems
constructor
A new instance of LockfileGems.
Constructor Details
#initialize(conf) ⇒ LockfileGems
Returns a new instance of LockfileGems.
14 15 16 17 18 |
# File 'lib/gems-status/sources/lockfile_gems.rb', line 14 def initialize(conf) Utils::check_parameters('LockfileGems', conf, ["filename", "gems_url"]) @filename = conf['filename'] @gems_url = conf['gems_url'] end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
13 14 15 |
# File 'lib/gems-status/sources/lockfile_gems.rb', line 13 def filename @filename end |
Instance Method Details
#gem_list ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gems-status/sources/lockfile_gems.rb', line 32 def gem_list gems = {} Utils::log_debug "reading #{@filename}" Dir.chdir(File.dirname(@filename)) do file_data = get_data(File::dirname(@filename), File::basename(@filename)) if file_data.empty? Utils::log_error("?", "file empty #{@filename}") return end lockfile = Bundler::LockfileParser.new(file_data) lockfile.specs.each do |spec| version = Gem::Version.create(spec.version) Utils::log_debug "dependencies for #{spec.name} #{spec.dependencies}" gems[spec.name] = GemSimple.new(spec.name, version , nil, @filename, gems_url(spec), spec.dependencies) end end gems end |
#get_data(dirname, filename) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gems-status/sources/lockfile_gems.rb', line 20 def get_data(dirname, filename) data = "" Dir.chdir(dirname) do begin data = File.open(filename).read rescue Utils::log_error("?", "There was a problem opening file #{filename} ") end end return data end |