Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5 Support #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

[![Gem Version](https://badge.fury.io/rb/postamt.png)](http://rubygems.org/gems/postamt)

Postamt is a sane, solution for performing database reads against a hot standby server with Rails 4.1 and 4.2.
Postamt is a sane solution for performing database reads against a hot standby server with Rails.

If you use Rails 3.2 or 4.0, use Postamt version 0.9.2.
For Rails 4.1 and above, the current Postamt version is `0.10.0`.
If you use Rails 3.2 or 4.0, use Postamt version `0.9.2`.

Choose per model and/or controller&action whether a read-only query
should be sent to master or a hot standby.<br />
Expand All @@ -20,8 +21,6 @@ through [officially-supported Rails
APIs](https://github.com/rails/rails/commit/ba1544d71628abff2777c9c514142d7e9a159111#commitcomment-2106059).
That's why there's so little code compared to similar gems.

Postamt requires Rails 3.2+ and works with Rails 4.

## Installation

Add this line to your application's Gemfile:
Expand Down
12 changes: 4 additions & 8 deletions lib/postamt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def self.overwritten_default_connections

# Called by Postamt::Railtie
def self.hook!
if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR <= 2
ActiveRecord::Base.default_connection_handler = Postamt::ConnectionHandler.new
elsif Rails::VERSION::MAJOR == 3 and Rails::VERSION::MINOR == 2
ActiveRecord::Base.connection_handler = Postamt::ConnectionHandler.new
end
ActiveRecord::Base.default_connection_handler = Postamt::ConnectionHandler.new

ActiveRecord::Base.instance_eval do
class_attribute :default_connection
Expand All @@ -73,7 +69,7 @@ def transaction(options = {}, &block)
def use_db_connection(connection, args)
klass_names = args.delete(:for)
if klass_names == :all
around_filter(args) do |controller|
around_action(args) do |controller|
Postamt.on(connection) { yield }
end
else
Expand All @@ -82,13 +78,13 @@ def use_db_connection(connection, args)
default_connections[klass_name] = connection
end

before_filter(args) do |controller|
before_action(args) do |controller|
Postamt.overwritten_default_connections.merge!(default_connections)
end
end
end

after_filter do
after_action do
Postamt.overwritten_default_connections.clear
end
end
Expand Down
14 changes: 2 additions & 12 deletions lib/postamt/connection_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,8 @@ def pool_for(klass)
@pools[connection] ||= begin
Postamt.configurations[connection.to_s] ||= Postamt.configurations['master']

spec = if Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR <= 2
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new Postamt.configurations
resolver.spec(connection)
elsif Rails::VERSION::MAJOR == 4 and Rails::VERSION::MINOR == 0
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new connection, Postamt.configurations
resolver.spec
elsif Rails::VERSION::MAJOR == 3 and Rails::VERSION::MINOR == 2
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new connection, Postamt.configurations
resolver.spec
else
abort "Postamt doesn't support Rails version #{Rails.version}"
end
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(Postamt.configurations)
spec = resolver.spec(connection)

unless ActiveRecord::Base.respond_to?(spec.adapter_method)
raise ActiveRecord::AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
Expand Down
2 changes: 1 addition & 1 deletion lib/postamt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Postamt
VERSION = "0.9.7"
VERSION = "0.10.0"
end
6 changes: 3 additions & 3 deletions postamt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 2.1.1'
spec.add_dependency "railties", ["~> 4.1", "< 4.3"]
spec.add_dependency "activerecord", ["~> 4.1", "< 4.3"]
spec.required_ruby_version = '>= 2.2.0'
spec.add_dependency "railties", [">= 4.1", "< 5.1"]
spec.add_dependency "activerecord", [">= 4.1", "< 5.1"]
spec.add_dependency "thread_safe", [">= 0.3.3"]
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
Expand Down
16 changes: 0 additions & 16 deletions testapp42/Gemfile

This file was deleted.

4 changes: 0 additions & 4 deletions testapp42/bin/rails

This file was deleted.

4 changes: 0 additions & 4 deletions testapp42/bin/rake

This file was deleted.

4 changes: 0 additions & 4 deletions testapp42/config.ru

This file was deleted.

24 changes: 0 additions & 24 deletions testapp42/config/application.rb

This file was deleted.

4 changes: 0 additions & 4 deletions testapp42/config/boot.rb

This file was deleted.

5 changes: 0 additions & 5 deletions testapp42/config/environment.rb

This file was deleted.

27 changes: 0 additions & 27 deletions testapp42/config/environments/development.rb

This file was deleted.

12 changes: 0 additions & 12 deletions testapp42/config/initializers/secret_token.rb

This file was deleted.

4 changes: 0 additions & 4 deletions testapp42/config/initializers/session_store.rb

This file was deleted.

49 changes: 0 additions & 49 deletions testapp42/config/routes.rb

This file was deleted.

10 changes: 0 additions & 10 deletions testapp42/db/seeds.rb

This file was deleted.

27 changes: 0 additions & 27 deletions testapp42/public/404.html

This file was deleted.

26 changes: 0 additions & 26 deletions testapp42/public/422.html

This file was deleted.

26 changes: 0 additions & 26 deletions testapp42/public/500.html

This file was deleted.

7 changes: 0 additions & 7 deletions testapp42/test/models/bar_test.rb

This file was deleted.

7 changes: 0 additions & 7 deletions testapp42/test/models/foo_test.rb

This file was deleted.

Empty file.
15 changes: 12 additions & 3 deletions testapp42/.gitignore → testapp50/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
Expand All @@ -7,6 +7,15 @@
# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore Byebug command history file.
.byebug_history
Loading