Sha256: 76685caccceec542387c40d76055a8969e350ba807b954dafef8e8171bf8c10c

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

namespace :uuids do

  desc "Installs the uuids gem inside a Rails application"
  task install: %w(install:migrations) do
    sh "rake db:migrate SCOPE=uuids"
  end

  desc "Uninstalls and removes the uuids gem from a Rails application"
  task :uninstall do
    sh "rake db:rollback SCOPE=uuids"
    remove_gem
    sh "bundle"
  end

  def remove_gem
    say "Removing the 'uuids' gem" do
      remove_from_file "Gemfile", /gem\s+["|']uuids["|']/
      Dir["*.gemspec"].each do |gemspec|
        remove_from_file gemspec, /_dependency\s+["|']uuids["|']/
      end
    end
  end

  def remove_from_file(name, regex)
    say_with_time name do
      temp = File.read(name).split("\n")
        .reject { |line| line[regex] }.join("\n")
      File.write(name, temp)
    end
  end

  def say(name)
    print "== #{ name } #{ "=" * (75 - name.count) }\n"
    yield
    print "\n"
  end

  def say_with_time(name)
    start = seconds
    print "-- remove from #{ name }\n"
    yield
    print "   -> #{ seconds - start }s\n"
  end

  def seconds
    Time.now.to_f.round(4)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uuids-0.2.0 lib/tasks/uuids_tasks.rake
uuids-0.1.0 lib/tasks/uuids_tasks.rake