“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it Currently working for GenieBelt who are based in Copenhagen, Denmark ...”

Rob Lacey
Senior Software Engineer, Copenhagen, Denmark

ActiveRecord extending scopes but not the base class

module QueryMethods
  def initialize_copy(other)
    super
    @__memo = {}      # reset cache on every copy
  end

  def count_from_schema
    @__memo ||= {}
    @__memo[:count_from_schema] ||= connection.select_value(%(
      SELECT TABLE_ROWS
      FROM information_schema.tables
      WHERE table_schema = DATABASE()
      AND table_name = '#{table_name}'
    ).squish)
  end
end

def self.default_scoped(scope = relation)
  super.extending(QueryMethods)
end