aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2019-02-07 11:59:45 -0800
committerJohn Hawthorn <john@hawthorn.email>2019-02-07 14:32:54 -0800
commita68bcde50660ba3adf4a2659f46212ad319cfeea (patch)
tree1145ff3f0faea8ef0e44c06fd3970a14f6c170d1 /activerecord
parented1f392ea6f3919aceda2d45f08cfa34780750f1 (diff)
downloadrails-a68bcde50660ba3adf4a2659f46212ad319cfeea.tar.gz
rails-a68bcde50660ba3adf4a2659f46212ad319cfeea.tar.bz2
rails-a68bcde50660ba3adf4a2659f46212ad319cfeea.zip
Rename database selector operations to context
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/middleware/database_selector.rb22
-rw-r--r--activerecord/lib/active_record/middleware/database_selector/resolver.rb14
2 files changed, 18 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/middleware/database_selector.rb b/activerecord/lib/active_record/middleware/database_selector.rb
index b95d8d6cb6..aad263695b 100644
--- a/activerecord/lib/active_record/middleware/database_selector.rb
+++ b/activerecord/lib/active_record/middleware/database_selector.rb
@@ -12,8 +12,8 @@ module ActiveRecord
#
# The resolver class defines when the application should switch (i.e. read
# from the primary if a write occurred less than 2 seconds ago) and an
- # operations class that sets a value that helps the resolver class decide
- # when to switch.
+ # resolver context class that sets a value that helps the resolver class
+ # decide when to switch.
#
# Rails default middleware uses the request's session to set a timestamp
# that informs the application when to read from a primary or read from a
@@ -24,7 +24,7 @@ module ActiveRecord
#
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
- # config.active_record.database_operations = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
+ # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
#
# New applications will include these lines commented out in the production.rb.
#
@@ -33,16 +33,16 @@ module ActiveRecord
#
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = MyResolver
- # config.active_record.database_operations = MyResolver::MySession
+ # config.active_record.database_resolver_context = MyResolver::MySession
class DatabaseSelector
- def initialize(app, resolver_klass = Resolver, operations_klass = Resolver::Session, options = {})
+ def initialize(app, resolver_klass = Resolver, context_klass = Resolver::Session, options = {})
@app = app
@resolver_klass = resolver_klass
- @operations_klass = operations_klass
+ @context_klass = context_klass
@options = options
end
- attr_reader :resolver_klass, :operations_klass, :options
+ attr_reader :resolver_klass, :context_klass, :options
# Middleware that determines which database connection to use in a multiple
# database application.
@@ -57,13 +57,13 @@ module ActiveRecord
private
def select_database(request, &blk)
- operations = operations_klass.call(request)
- database_resolver = resolver_klass.call(operations, options)
+ context = context_klass.call(request)
+ resolver = resolver_klass.call(context, options)
if reading_request?(request)
- database_resolver.read(&blk)
+ resolver.read(&blk)
else
- database_resolver.write(&blk)
+ resolver.write(&blk)
end
end
diff --git a/activerecord/lib/active_record/middleware/database_selector/resolver.rb b/activerecord/lib/active_record/middleware/database_selector/resolver.rb
index 775be95e0b..80b8cd7cae 100644
--- a/activerecord/lib/active_record/middleware/database_selector/resolver.rb
+++ b/activerecord/lib/active_record/middleware/database_selector/resolver.rb
@@ -18,18 +18,18 @@ module ActiveRecord
class Resolver # :nodoc:
SEND_TO_REPLICA_DELAY = 2.seconds
- def self.call(operations, options = {})
- new(operations, options)
+ def self.call(context, options = {})
+ new(context, options)
end
- def initialize(operations, options = {})
- @operations = operations
+ def initialize(context, options = {})
+ @context = context
@options = options
@delay = @options && @options[:delay] ? @options[:delay] : SEND_TO_REPLICA_DELAY
@instrumenter = ActiveSupport::Notifications.instrumenter
end
- attr_reader :operations, :delay, :instrumenter
+ attr_reader :context, :delay, :instrumenter
def read(&blk)
if read_from_primary?
@@ -68,7 +68,7 @@ module ActiveRecord
instrumenter.instrument("database_selector.active_record.wrote_to_primary") do
yield
ensure
- operations.update_last_write_timestamp
+ context.update_last_write_timestamp
end
end
end
@@ -82,7 +82,7 @@ module ActiveRecord
end
def time_since_last_write_ok?
- Time.now - operations.last_write_timestamp >= send_to_replica_delay
+ Time.now - context.last_write_timestamp >= send_to_replica_delay
end
end
end