This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const documentsStrategyOptions = { | |
cacheName: `documents-${CACHE_VERSION}`, | |
matchOptions: { ignoreVary: true }, | |
plugins: [ | |
new ExpirationPlugin({ | |
maxEntries: 100 | |
}) | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global self, clients, importScripts, workbox */ | |
importScripts( | |
"https://storage.googleapis.com/workbox-cdn/releases/7.3.0/workbox-sw.js" | |
); | |
// workbox sw chrome console logging is on by default for localhost | |
// but let's turn it on for production too | |
// see https://developer.chrome.com/docs/workbox/troubleshooting-and-logging#without_a_bundler | |
workbox.setConfig({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "#{Gem.loaded_specs['activerecord'].full_gem_path}/lib/active_record/connection_adapters/abstract_adapter" | |
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractAdapter | |
# we are overriding this method since connection_klass is a string when accessing a MyGem db | |
def preventing_writes? | |
return true if replica? | |
return ActiveRecord::Base.connection_handler.prevent_writes if ActiveRecord::Base.legacy_connection_handling | |
# commented out line below and replaced with an expanded guard clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyGem | |
class BaseRecord < ActiveRecord::Base | |
self.abstract_class = true | |
class << self | |
# What we are doing here is creating a connection pool for each db on class load | |
# (see bottom of class) and we override 2 active record base class methods for | |
# establishing and retrieving each db connection | |
# This method overrides the one in ActiveRecord::ConnectionHandling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: &default | |
encoding: utf8 | |
adapter: mysql2 | |
port: <%= ENV['MYGEM_DATABASE_PORT'] %> | |
host: <%= ENV['MYGEM_DATABASE_HOST'] %> | |
username: <%= ENV['MYGEM_DATABASE_USERNAME'] %> | |
password: <%= ENV['MYGEM_DATABASE_PASSWORD'] %> | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
development: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyGem | |
class DbConfig | |
CONFIGURATIONS = Psych.safe_load( | |
ERB.new( | |
File.read(File.join(File.dirname(__FILE__), '../../config/databases.yml')) | |
).result, | |
aliases: true | |
) | |
DB_ENV = (Rails.env if defined?(Rails)) || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyGem | |
class BaseRecord < ActiveRecord::Base | |
self.abstract_class = true | |
class << self | |
# What we are doing here is creating a connection pool for each db on class load | |
# (see bottom of class) and we override 2 active record base class methods for | |
# establishing and retrieving each db connection | |
# This method overrides the one in ActiveRecord::ConnectionHandling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: ':memory:' | |
) | |
ActiveRecord::Schema.define do | |
create_table :people do |table| | |
table.column :name, :string |