class Papers::ManifestUpdater
Public Instance Methods
delete_gems(result_gems, manifest_names)
click to toggle source
# File lib/papers/manifest_updater.rb, line 95 def delete_gems(result_gems, manifest_names) # Find removed gems manifest_names.each do |(gem_name, gem_key)| if gemspecs.none? { |gem| gem.name == gem_name } result_gems.delete(gem_key) end end end
gemspecs()
click to toggle source
# File lib/papers/manifest_updater.rb, line 115 def gemspecs @gemspecs ||= Bundler.load.specs.dup end
manifest_names(result_gems)
click to toggle source
# File lib/papers/manifest_updater.rb, line 108 def manifest_names(result_gems) result_gems.reduce({}) do |hash, (key, _)| hash[name_from_key(key)] = key hash end end
name_from_key(key)
click to toggle source
# File lib/papers/manifest_updater.rb, line 104 def name_from_key(key) key.include?('-') ? key.rpartition('-').first : key end
new_gem(result_gems, gemspec)
click to toggle source
# File lib/papers/manifest_updater.rb, line 91 def new_gem(result_gems, gemspec) result_gems[gem_name_and_version(gemspec)] = gem_entry(gemspec) end
update()
click to toggle source
# File lib/papers/manifest_updater.rb, line 23 def update raise Papers::FileMissingError.new(@manifest_path) unless manifest_exists? original_content = File.read(@manifest_path) result = YAML.load(original_content) update_gems(result) update_javascript(result, 'javascripts', get_installed_javascripts) update_javascript(result, 'bower_components', get_installed_bower_components) update_javascript(result, 'npm_packages', get_installed_npm_packages) manifest_content = build_header + YAML.dump(result) # strip trailing whitespace, ensure file ends with a newline manifest_content.gsub(/\s*$/, '') + "\n" end
update!()
click to toggle source
# File lib/papers/manifest_updater.rb, line 14 def update! updated_content = update File.open(@manifest_path, 'w') do |file| file.write(updated_content) end puts "Updated #{@manifest_path}! Run your tests and check your diffs!" end
update_gem(result_gems, gemspec, manifest_gem_key)
click to toggle source
# File lib/papers/manifest_updater.rb, line 73 def update_gem(result_gems, gemspec, manifest_gem_key) manifest_gem = result_gems.delete(manifest_gem_key) if gemspec.license && gemspec.license != manifest_gem['license'] new_licenses = gemspec.licenses || [] new_licenses << gemspec.license new_licenses.uniq! # license key could be an array to_s to protect against that unless manifest_gem['license'].to_s.match(/^License Change! Was '.+', is now .+$/) manifest_gem['license'] = "License Change! Was '#{manifest_gem['license']}', is now #{new_licenses}" end end name = gem_name_and_version(gemspec) name = gemspec.name if gemspec.name == manifest_gem_key result_gems[name] = manifest_gem end
update_gems(result)
click to toggle source
# File lib/papers/manifest_updater.rb, line 40 def update_gems(result) result_gems = result['gems'] return unless result_gems manifest_names = manifest_names(result_gems) gemspecs.each do |gemspec| if manifest_gem_key = manifest_names[gemspec.name] update_gem(result_gems, gemspec, manifest_gem_key) else new_gem(result_gems, gemspec) end end delete_gems(result_gems, manifest_names) end
update_javascript(result, key, installed)
click to toggle source
# File lib/papers/manifest_updater.rb, line 56 def update_javascript(result, key, installed) existing = result[key] return unless existing && installed removed = existing.keys - installed.keys # Merge over new results from existing to keep edits installed.merge!(existing) # Remove things that aren't installed anymore removed.each do |remove| installed.delete(remove) end result[key] = installed end