Module: Gem::Prune::Util

Included in:
Commands::KeepCommand, Commands::PruneCommand
Defined in:
lib/gem/prune/util.rb

Instance Method Summary collapse

Instance Method Details

#gems_to_keepObject



7
8
9
# File 'lib/gem/prune/util.rb', line 7

def gems_to_keep
  @configuration
end

#load_configurationObject



11
12
13
14
15
16
17
# File 'lib/gem/prune/util.rb', line 11

def load_configuration
  @configuration ||= File.read(settings_filename).split("\n").map do |line|
    gem, versions = line.split(' ', 2)
    versions = versions.to_s.gsub(/[\(\)]/, '').split(', ')
    [gem, versions]
  end
end

#save_configurationObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/gem/prune/util.rb', line 19

def save_configuration
  File.open(settings_filename, "w") do |file|
    formatted = @configuration.sort_by(&:first).map do |gem, versions|
      version_string = versions.length.zero? ? "" : " (%s)" % versions.join(", ")
      "#{gem}#{version_string}"
    end.join("\n")

    file.puts formatted
  end
end

#settings_filenameObject



3
4
5
# File 'lib/gem/prune/util.rb', line 3

def settings_filename
  File.expand_path('~/.gem-prune')
end