activerecord-refresh_connection 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +14 -0
- data/activerecord-refresh_connection.gemspec +27 -0
- data/example/.gitignore +16 -0
- data/example/Gemfile +41 -0
- data/example/README.rdoc +28 -0
- data/example/Rakefile +6 -0
- data/example/app/assets/images/.keep +0 -0
- data/example/app/assets/javascripts/application.js +16 -0
- data/example/app/assets/javascripts/articles.js.coffee +3 -0
- data/example/app/assets/javascripts/books.js.coffee +3 -0
- data/example/app/assets/stylesheets/application.css +15 -0
- data/example/app/assets/stylesheets/articles.css.scss +3 -0
- data/example/app/assets/stylesheets/books.css.scss +3 -0
- data/example/app/assets/stylesheets/scaffolds.css.scss +69 -0
- data/example/app/controllers/application_controller.rb +5 -0
- data/example/app/controllers/articles_controller.rb +74 -0
- data/example/app/controllers/books_controller.rb +74 -0
- data/example/app/controllers/concerns/.keep +0 -0
- data/example/app/helpers/application_helper.rb +2 -0
- data/example/app/helpers/articles_helper.rb +2 -0
- data/example/app/helpers/books_helper.rb +2 -0
- data/example/app/mailers/.keep +0 -0
- data/example/app/models/.keep +0 -0
- data/example/app/models/article.rb +2 -0
- data/example/app/models/book.rb +2 -0
- data/example/app/models/concerns/.keep +0 -0
- data/example/app/views/articles/_form.html.erb +21 -0
- data/example/app/views/articles/edit.html.erb +6 -0
- data/example/app/views/articles/index.html.erb +25 -0
- data/example/app/views/articles/index.json.jbuilder +4 -0
- data/example/app/views/articles/new.html.erb +5 -0
- data/example/app/views/articles/show.html.erb +9 -0
- data/example/app/views/articles/show.json.jbuilder +1 -0
- data/example/app/views/books/_form.html.erb +21 -0
- data/example/app/views/books/edit.html.erb +6 -0
- data/example/app/views/books/index.html.erb +25 -0
- data/example/app/views/books/index.json.jbuilder +4 -0
- data/example/app/views/books/new.html.erb +5 -0
- data/example/app/views/books/show.html.erb +9 -0
- data/example/app/views/books/show.json.jbuilder +1 -0
- data/example/app/views/layouts/application.html.erb +14 -0
- data/example/bin/bundle +3 -0
- data/example/bin/rails +4 -0
- data/example/bin/rake +4 -0
- data/example/config.ru +4 -0
- data/example/config/application.rb +26 -0
- data/example/config/boot.rb +4 -0
- data/example/config/database.yml +18 -0
- data/example/config/environment.rb +5 -0
- data/example/config/environments/development.rb +37 -0
- data/example/config/environments/production.rb +83 -0
- data/example/config/environments/test.rb +39 -0
- data/example/config/initializers/backtrace_silencers.rb +7 -0
- data/example/config/initializers/cookies_serializer.rb +3 -0
- data/example/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/config/initializers/inflections.rb +16 -0
- data/example/config/initializers/mime_types.rb +4 -0
- data/example/config/initializers/session_store.rb +3 -0
- data/example/config/initializers/wrap_parameters.rb +14 -0
- data/example/config/locales/en.yml +23 -0
- data/example/config/routes.rb +60 -0
- data/example/config/secrets.yml +22 -0
- data/example/db/migrate/20140623044349_create_books.rb +9 -0
- data/example/db/migrate/20140623044357_create_articles.rb +9 -0
- data/example/db/schema.rb +28 -0
- data/example/db/seeds.rb +7 -0
- data/example/lib/assets/.keep +0 -0
- data/example/lib/tasks/.keep +0 -0
- data/example/log/.keep +0 -0
- data/example/public/404.html +67 -0
- data/example/public/422.html +67 -0
- data/example/public/500.html +66 -0
- data/example/public/favicon.ico +0 -0
- data/example/public/robots.txt +5 -0
- data/example/test/controllers/.keep +0 -0
- data/example/test/controllers/articles_controller_test.rb +49 -0
- data/example/test/controllers/books_controller_test.rb +49 -0
- data/example/test/fixtures/.keep +0 -0
- data/example/test/fixtures/articles.yml +7 -0
- data/example/test/fixtures/books.yml +7 -0
- data/example/test/helpers/.keep +0 -0
- data/example/test/helpers/articles_helper_test.rb +4 -0
- data/example/test/helpers/books_helper_test.rb +4 -0
- data/example/test/integration/.keep +0 -0
- data/example/test/mailers/.keep +0 -0
- data/example/test/models/.keep +0 -0
- data/example/test/models/article_test.rb +7 -0
- data/example/test/models/book_test.rb +7 -0
- data/example/test/test_helper.rb +13 -0
- data/example/vendor/assets/javascripts/.keep +0 -0
- data/example/vendor/assets/stylesheets/.keep +0 -0
- data/lib/activerecord-refresh_connection.rb +1 -0
- data/lib/activerecord-refresh_connection/active_record/connection_adapters/refresh_connection_management.rb +24 -0
- data/spec/spec_helper.rb +15 -0
- metadata +229 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
class BooksController < ApplicationController
|
2
|
+
before_action :set_book, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /books
|
5
|
+
# GET /books.json
|
6
|
+
def index
|
7
|
+
@books = Book.all
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /books/1
|
11
|
+
# GET /books/1.json
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /books/new
|
16
|
+
def new
|
17
|
+
@book = Book.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /books/1/edit
|
21
|
+
def edit
|
22
|
+
end
|
23
|
+
|
24
|
+
# POST /books
|
25
|
+
# POST /books.json
|
26
|
+
def create
|
27
|
+
@book = Book.new(book_params)
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
if @book.save
|
31
|
+
format.html { redirect_to @book, notice: 'Book was successfully created.' }
|
32
|
+
format.json { render :show, status: :created, location: @book }
|
33
|
+
else
|
34
|
+
format.html { render :new }
|
35
|
+
format.json { render json: @book.errors, status: :unprocessable_entity }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# PATCH/PUT /books/1
|
41
|
+
# PATCH/PUT /books/1.json
|
42
|
+
def update
|
43
|
+
respond_to do |format|
|
44
|
+
if @book.update(book_params)
|
45
|
+
format.html { redirect_to @book, notice: 'Book was successfully updated.' }
|
46
|
+
format.json { render :show, status: :ok, location: @book }
|
47
|
+
else
|
48
|
+
format.html { render :edit }
|
49
|
+
format.json { render json: @book.errors, status: :unprocessable_entity }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# DELETE /books/1
|
55
|
+
# DELETE /books/1.json
|
56
|
+
def destroy
|
57
|
+
@book.destroy
|
58
|
+
respond_to do |format|
|
59
|
+
format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' }
|
60
|
+
format.json { head :no_content }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
# Use callbacks to share common setup or constraints between actions.
|
66
|
+
def set_book
|
67
|
+
@book = Book.find(params[:id])
|
68
|
+
end
|
69
|
+
|
70
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
71
|
+
def book_params
|
72
|
+
params.require(:book).permit(:title)
|
73
|
+
end
|
74
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= form_for(@article) do |f| %>
|
2
|
+
<% if @article.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @article.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br>
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="actions">
|
19
|
+
<%= f.submit %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing articles</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Title</th>
|
7
|
+
<th colspan="3"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
|
11
|
+
<tbody>
|
12
|
+
<% @articles.each do |article| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= article.title %></td>
|
15
|
+
<td><%= link_to 'Show', article %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_article_path(article) %></td>
|
17
|
+
<td><%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New Article', new_article_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
json.extract! @article, :id, :title, :created_at, :updated_at
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= form_for(@book) do |f| %>
|
2
|
+
<% if @book.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@book.errors.count, "error") %> prohibited this book from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @book.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br>
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="actions">
|
19
|
+
<%= f.submit %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing books</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Title</th>
|
7
|
+
<th colspan="3"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
|
11
|
+
<tbody>
|
12
|
+
<% @books.each do |book| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= book.title %></td>
|
15
|
+
<td><%= link_to 'Show', book %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_book_path(book) %></td>
|
17
|
+
<td><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New Book', new_book_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
json.extract! @book, :id, :title, :created_at, :updated_at
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Blog</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/example/bin/bundle
ADDED
data/example/bin/rails
ADDED
data/example/bin/rake
ADDED
data/example/config.ru
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module Blog
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
16
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
17
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
18
|
+
|
19
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
20
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
21
|
+
# config.i18n.default_locale = :de
|
22
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
23
|
+
config.middleware.swap ActiveRecord::ConnectionAdapters::ConnectionManagement,
|
24
|
+
"ActiveRecord::ConnectionAdapters::RefreshConnectionManagement"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: mysql2
|
3
|
+
database: activerecord-refresh_connection
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
username: root
|
7
|
+
password:
|
8
|
+
host: localhost
|
9
|
+
port: 3306
|
10
|
+
|
11
|
+
development:
|
12
|
+
<<: *default
|
13
|
+
|
14
|
+
test:
|
15
|
+
<<: *default
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *default
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations.
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
|
30
|
+
# Adds additional error checking when serving assets at runtime.
|
31
|
+
# Checks for improperly declared sprockets dependencies.
|
32
|
+
# Raises helpful error messages.
|
33
|
+
config.assets.raise_runtime_errors = true
|
34
|
+
|
35
|
+
# Raises error for missing translations
|
36
|
+
# config.action_view.raise_on_missing_translations = true
|
37
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# Code is not reloaded between requests.
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both threaded web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on.
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
|
+
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
+
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
|
20
|
+
# config.action_dispatch.rack_cache = true
|
21
|
+
|
22
|
+
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
+
config.serve_static_assets = false
|
24
|
+
|
25
|
+
# Compress JavaScripts and CSS.
|
26
|
+
config.assets.js_compressor = :uglifier
|
27
|
+
# config.assets.css_compressor = :sass
|
28
|
+
|
29
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
30
|
+
config.assets.compile = false
|
31
|
+
|
32
|
+
# Generate digests for assets URLs.
|
33
|
+
config.assets.digest = true
|
34
|
+
|
35
|
+
# Version of your assets, change this if you want to expire all your assets.
|
36
|
+
config.assets.version = '1.0'
|
37
|
+
|
38
|
+
# Specifies the header that your server uses for sending files.
|
39
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
40
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
41
|
+
|
42
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
43
|
+
# config.force_ssl = true
|
44
|
+
|
45
|
+
# Set to :debug to see everything in the log.
|
46
|
+
config.log_level = :info
|
47
|
+
|
48
|
+
# Prepend all log lines with the following tags.
|
49
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
50
|
+
|
51
|
+
# Use a different logger for distributed setups.
|
52
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
53
|
+
|
54
|
+
# Use a different cache store in production.
|
55
|
+
# config.cache_store = :mem_cache_store
|
56
|
+
|
57
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
58
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
59
|
+
|
60
|
+
# Precompile additional assets.
|
61
|
+
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
62
|
+
# config.assets.precompile += %w( search.js )
|
63
|
+
|
64
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
65
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
66
|
+
# config.action_mailer.raise_delivery_errors = false
|
67
|
+
|
68
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
69
|
+
# the I18n.default_locale when a translation cannot be found).
|
70
|
+
config.i18n.fallbacks = true
|
71
|
+
|
72
|
+
# Send deprecation notices to registered listeners.
|
73
|
+
config.active_support.deprecation = :notify
|
74
|
+
|
75
|
+
# Disable automatic flushing of the log to improve performance.
|
76
|
+
# config.autoflush_log = false
|
77
|
+
|
78
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
79
|
+
config.log_formatter = ::Logger::Formatter.new
|
80
|
+
|
81
|
+
# Do not dump schema after migrations.
|
82
|
+
config.active_record.dump_schema_after_migration = false
|
83
|
+
end
|