Skip to content

Instantly share code, notes, and snippets.

View trushkevich's full-sized avatar

Anton Trushkevich trushkevich

View GitHub Profile
module ActiveRecordGroupCount
extend ActiveSupport::Concern
module ExtensionMethods
def count(*args)
scope = except(:select).select("1")
query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x"
ActiveRecord::Base.connection.execute(query).first.first
end
end
@trushkevich
trushkevich / deploy.rb
Last active June 9, 2016 15:08
Capistrano 3 private_pub tasks
set :private_pub_pid, -> { "#{current_path}/tmp/pids/private_pub.pid" }
namespace :private_pub do
desc "Start private_pub server"
task :start do
on roles(:app) do
within release_path do
with rails_env: fetch(:stage) do
execute :bundle, "exec thin -C config/private_pub/thin_#{fetch(:stage)}.yml -d -P #{fetch(:private_pub_pid)} start"
end