Module: Lapidario
- Defined in:
- lib/cli.rb,
lib/helper.rb,
lib/lapidario.rb,
lib/gemfile_info.rb,
lib/lockfile_info.rb,
lib/lapidario/version.rb
Defined Under Namespace
Modules: Helper Classes: CLI, Error, GemfileInfo, LockfileInfo
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
-
.build_new_gemfile(new_gemfile_info, original_gemfile_lines) ⇒ Object
semi-final step: build new temporary gemfile, replacing changed lines in the original; intermediary object will be altered by one of the methods at the bottom of the page.
-
.get_gemfile_and_lockfile_info(project_path_hash, include_git_gems = false) ⇒ Object
first step: build gemfile and lockfile info instances input: project_path_hash; has either :project_path key or both :gemfile_path and :lockfile_path; returns GemfileInfo and LockfileInfo instances.
-
.hardcode_gemfile_with_empty_versions(gemfile_info, keep_extra_info = true) ⇒ Object
soft reset of gemfile, removing all version information.
-
.hardcode_lockfile_versions_into_gemfile_info(gemfile_info, lockfile_info, default_sign = '~>', default_depth = 2) ⇒ Object
loops through lockfile info, collecting versions hard-codes these versions on gemfile, as they might differ from the lockfile’s will use ‘~>’ as default sign and 2 as default depth.
-
.save_gemfiles(save_path, new_gemfile, original_gemfile) ⇒ Object
final step: save new, backup old.
Class Method Details
.build_new_gemfile(new_gemfile_info, original_gemfile_lines) ⇒ Object
semi-final step: build new temporary gemfile, replacing changed lines in the original; intermediary object will be altered by one of the methods at the bottom of the page
32 33 34 35 36 37 38 39 |
# File 'lib/lapidario.rb', line 32 def self.build_new_gemfile(new_gemfile_info, original_gemfile_lines) new_gemfile = original_gemfile_lines.clone new_gemfile_info.each do |info_item| new_line = Lapidario::GemfileInfo.build_gemfile_line(info_item) new_gemfile[info_item[:line_index]] = new_line end new_gemfile end |
.get_gemfile_and_lockfile_info(project_path_hash, include_git_gems = false) ⇒ Object
first step: build gemfile and lockfile info instances input: project_path_hash; has either :project_path key or both :gemfile_path and :lockfile_path; returns GemfileInfo and LockfileInfo instances
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lapidario.rb', line 16 def self.get_gemfile_and_lockfile_info(project_path_hash, include_git_gems = false) project_path = project_path_hash[:project_path] if (project_path && !project_path.empty?) gemfile_path, lockfile_path = Lapidario::Helper.format_path(project_path, false), Lapidario::Helper.format_path(project_path, true) elsif !(project_path_hash[:gemfile_path] && !project_path_hash[:gemfile_path].empty?) && !(project_path_hash[:lockfile_path] && !project_path_hash[:lockfile_path].empty?) raise Lapidario::Error, "Double-check input for project path." else gemfile_path, lockfile_path = Lapidario::Helper.format_path(project_path_hash[:gemfile_path], false), Lapidario::Helper.format_path(project_path_hash[:lockfile_path], true) end gemfile_info = Lapidario::GemfileInfo.new(Lapidario::Helper.get_file_as_array_of_lines(gemfile_path)) lockfile_info = Lapidario::LockfileInfo.new(Lapidario::Helper.get_file_as_array_of_lines(lockfile_path), include_git_gems) [gemfile_info, lockfile_info] end |
.hardcode_gemfile_with_empty_versions(gemfile_info, keep_extra_info = true) ⇒ Object
soft reset of gemfile, removing all version information. Removing extra info is optional Note: if a version is ranged and extra info is keps, this will also hard-code the version upper range in the gem line.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/lapidario.rb', line 81 def self.hardcode_gemfile_with_empty_versions(gemfile_info, keep_extra_info = true) new_gemfile_info = gemfile_info.gemfile_lines_info.clone # replace versions in gemfile with ones on lockfile new_gemfile_info.each do |gem_info| gem_info[:current_version] = "" gem_info[:version_sign] = "" gem_info[:extra_info] = "" unless keep_extra_info end new_gemfile_info end |
.hardcode_lockfile_versions_into_gemfile_info(gemfile_info, lockfile_info, default_sign = '~>', default_depth = 2) ⇒ Object
loops through lockfile info, collecting versions hard-codes these versions on gemfile, as they might differ from the lockfile’s will use ‘~>’ as default sign and 2 as default depth
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lapidario.rb', line 58 def self.hardcode_lockfile_versions_into_gemfile_info(gemfile_info, lockfile_info, default_sign = '~>', default_depth = 2) new_gemfile_info = gemfile_info.gemfile_lines_info.clone lockfile_primary_gems = lockfile_info.primary_gems # replace versions in gemfile with ones on lockfile new_gemfile_info.each do |gem_info| lock_version = lockfile_primary_gems[gem_info[:name]] if lock_version # if git version, add remote to extra info before extracting version if lock_version.match?(/git:/) remote = lock_version.split(",")[1].strip lock_version = lock_version.split(",")[0] gem_info[:extra_info] << remote end gem_info[:current_version] = lock_version gem_info[:current_version] = Lapidario::Helper.format_version_based_on_depth(lock_version, default_depth) if default_depth gem_info[:version_sign] = default_sign end end new_gemfile_info end |
.save_gemfiles(save_path, new_gemfile, original_gemfile) ⇒ Object
final step: save new, backup old
42 43 44 45 46 47 48 49 |
# File 'lib/lapidario.rb', line 42 def self.save_gemfiles(save_path, new_gemfile, original_gemfile) # save original gemfile as backup original_save_path = Lapidario::Helper.format_path(save_path) + ".original" Lapidario::Helper.save_file(original_save_path, original_gemfile.join("\n")) # overwrite current Gemfile with new content new_save_path = Lapidario::Helper.format_path(save_path) Lapidario::Helper.save_file(new_save_path, new_gemfile.join("\n")) end |