module GemHelpers

Public Instance Methods

build_gemfile() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 35
def build_gemfile
  fix_withespace_issues if call_gem_for_gathered_gems
end
clean_gemfile() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 30
def clean_gemfile
  remove_everything_but_source
  add_original_rails_gems
end
discard_gem(name) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 14
def discard_gem(name)
  ensure_variable(:gems, {})
  get(:gems).each do |_environments, gems|
    gems.delete_if do |gem_entry|
      gem_entry[:name] == name
    end
  end
end
gather_gem(name, *attributes) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 6
def gather_gem(name, *attributes)
  ensure_variable(:gems, {})
  current_gem_groups = get(:current_gem_groups) || [:base]

  get(:gems)[current_gem_groups] ||= []
  get(:gems)[current_gem_groups] << { name: name, attributes: attributes }
end
gather_gems(*environments, &block) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 23
def gather_gems(*environments, &block)
  ensure_variable(:gems, {})
  set(:current_gem_groups, environments)
  instance_exec(&block)
  set(:current_gem_groups, [:base])
end
gem_exists?(regexp) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 2
def gem_exists?(regexp)
  File.open("Gemfile").each_line.any? { |line| line =~ regexp }
end

Private Instance Methods

add_original_rails_gems() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 69
def add_original_rails_gems
  gemfile_entries.each do |entry|
    unless entry.commented_out
      gather_gem(entry.name, version: entry[:version])
    end
  end
end
call_gem_for_gathered_gems() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 41
def call_gem_for_gathered_gems
  ensure_variable(:gems, {})
  gems = get(:gems)

  return false if gems.empty?

  base_gems = gems.delete([:base]) || []

  call_gem_for_gems(base_gems)

  gems.each do |environments, env_gems|
    gem_group *environments do
      call_gem_for_gems(env_gems)
    end
  end

  true
end
call_gem_for_gem(gem_data) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 65
def call_gem_for_gem(gem_data)
  gem gem_data[:name], *gem_data[:attributes]
end
call_gem_for_gems(gems) click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 60
def call_gem_for_gems(gems)
  gems.sort_by! { |k| k[:name] }
  gems.each(&method(:call_gem_for_gem))
end
fix_withespace_issues() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 81
def fix_withespace_issues
  gsub_file("Gemfile", /^group/, "\ngroup")
  gsub_file("Gemfile", /^\n\n/, "\n")
end
remove_everything_but_source() click to toggle source
# File lib/potassium/helpers/gem-helpers.rb, line 77
def remove_everything_but_source
  gsub_file("Gemfile", /[\w\W]+/, "source 'https://rubygems.org'\n")
end