rails_web_cache 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +21 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +11 -0
  6. data/Gemfile +15 -0
  7. data/Gemfile.lock +178 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +43 -0
  10. data/Rakefile +28 -0
  11. data/app/assets/config/rails_web_cache_manifest.js +2 -0
  12. data/app/assets/images/rails_web_cache/.keep +0 -0
  13. data/app/assets/javascripts/rails_web_cache/application.js +17 -0
  14. data/app/assets/javascripts/rails_web_cache/bootstrap.js +6 -0
  15. data/app/assets/javascripts/rails_web_cache/jquery.js +2 -0
  16. data/app/assets/javascripts/rails_web_cache/keys.js +22 -0
  17. data/app/assets/javascripts/rails_web_cache/popper.js +5 -0
  18. data/app/assets/stylesheets/rails_web_cache/application.css +14 -0
  19. data/app/assets/stylesheets/rails_web_cache/bootstrap.css +7 -0
  20. data/app/controllers/rails_web_cache/application_controller.rb +7 -0
  21. data/app/controllers/rails_web_cache/keys_controller.rb +84 -0
  22. data/app/helpers/rails_web_cache/keys_helper.rb +18 -0
  23. data/app/views/layouts/rails_web_cache/application.html.erb +16 -0
  24. data/app/views/rails_web_cache/keys/index.html.erb +95 -0
  25. data/app/views/rails_web_cache/keys/show.html.erb +26 -0
  26. data/app/views/rails_web_cache/shared/_header.html.erb +17 -0
  27. data/bin/rails +20 -0
  28. data/config/routes.rb +11 -0
  29. data/lib/rails_web_cache/base.rb +44 -0
  30. data/lib/rails_web_cache/engine.rb +21 -0
  31. data/lib/rails_web_cache/entry.rb +19 -0
  32. data/lib/rails_web_cache/file_store.rb +9 -0
  33. data/lib/rails_web_cache/memory_store.rb +9 -0
  34. data/lib/rails_web_cache/redis_cache_store.rb +23 -0
  35. data/lib/rails_web_cache/version.rb +5 -0
  36. data/lib/rails_web_cache.rb +46 -0
  37. data/rails_web_cache.gemspec +39 -0
  38. data/spec/controllers/keys_controller_spec.rb +41 -0
  39. data/spec/dummy/Rakefile +6 -0
  40. data/spec/dummy/app/assets/config/manifest.js +3 -0
  41. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  42. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  44. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  45. data/spec/dummy/bin/bundle +5 -0
  46. data/spec/dummy/bin/rails +6 -0
  47. data/spec/dummy/bin/rake +6 -0
  48. data/spec/dummy/bin/setup +38 -0
  49. data/spec/dummy/bin/update +33 -0
  50. data/spec/dummy/bin/yarn +13 -0
  51. data/spec/dummy/config/application.rb +23 -0
  52. data/spec/dummy/config/boot.rb +7 -0
  53. data/spec/dummy/config/environment.rb +7 -0
  54. data/spec/dummy/config/environments/development.rb +47 -0
  55. data/spec/dummy/config/environments/production.rb +74 -0
  56. data/spec/dummy/config/environments/test.rb +40 -0
  57. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  58. data/spec/dummy/config/initializers/assets.rb +14 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  60. data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
  61. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  63. data/spec/dummy/config/initializers/inflections.rb +18 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +11 -0
  66. data/spec/dummy/config/locales/en.yml +33 -0
  67. data/spec/dummy/config/puma.rb +39 -0
  68. data/spec/dummy/config/routes.rb +5 -0
  69. data/spec/dummy/config/spring.rb +8 -0
  70. data/spec/dummy/config.ru +7 -0
  71. data/spec/dummy/log/development.log +630 -0
  72. data/spec/dummy/log/test.log +1791 -0
  73. data/spec/dummy/public/404.html +67 -0
  74. data/spec/dummy/public/422.html +67 -0
  75. data/spec/dummy/public/500.html +66 -0
  76. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  77. data/spec/dummy/public/apple-touch-icon.png +0 -0
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/dummy/tmp/development_secret.txt +1 -0
  80. data/spec/helpers/keys_helper_spec.rb +28 -0
  81. data/spec/rails_helper.rb +50 -0
  82. data/spec/rails_web_cache_spec.rb +37 -0
  83. data/spec/routing/keys_controller_spec.rb +31 -0
  84. data/spec/spec_helper.rb +101 -0
  85. metadata +237 -0
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ # Maintain your gem's version:
6
+ require 'rails_web_cache/version'
7
+
8
+ # Describe your gem and declare its dependencies:
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'rails_web_cache'
11
+ spec.version = RailsWebCache::VERSION
12
+ spec.authors = ['Boris BRESCIANI']
13
+ spec.email = ['boris2bresciani@gmail.com']
14
+
15
+ spec.summary = 'Manage rails cache by Web UI'
16
+ spec.description = 'Manage rails cache by Web UI (Redis, Memory, etc...)'
17
+ spec.homepage = 'https://github.com/BorisBresciani/rails_web_cache'
18
+ spec.license = 'MIT'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0")
27
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+ spec.test_files = Dir['spec/**/*']
33
+
34
+ spec.add_development_dependency 'coveralls', '~> 0.8'
35
+ spec.add_development_dependency 'rspec-rails', '= 4.0.0.beta3'
36
+ spec.add_development_dependency 'simplecov', '~> 0.16'
37
+
38
+ spec.add_dependency 'rails', '>= 5.2', '< 7.0'
39
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RailsWebCache::KeysController, type: :controller do
6
+ routes { RailsWebCache::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ it 'returns a success response' do
10
+ Rails.cache.write('RailsWebCache', 'RailsWebCache')
11
+ get :index
12
+ expect(response).to be_successful
13
+ get :index, params: { query: 'Search' }
14
+ expect(response).to be_successful
15
+ end
16
+ end
17
+
18
+ describe 'GET #show' do
19
+ it 'returns a success response' do
20
+ Rails.cache.write('RailsWebCache', 'RailsWebCache')
21
+ get :show, params: { key: 'RailsWebCache' }
22
+ expect(response).to be_successful
23
+ end
24
+ end
25
+
26
+ describe 'GET #destroy' do
27
+ it 'returns a success response' do
28
+ Rails.cache.write('RailsWebCache', 'RailsWebCache')
29
+ get :destroy, params: { key: 'RailsWebCache' }
30
+ expect(response).to be_redirect
31
+ end
32
+ end
33
+
34
+ describe 'GET #destroy_all' do
35
+ it 'returns a success response' do
36
+ Rails.cache.write('RailsWebCache', 'RailsWebCache')
37
+ get :destroy_all, params: { keys: ['RailsWebCache'] }
38
+ expect(response).to be_redirect
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_directory ../stylesheets .css
2
+ //= link_directory ../javascripts .css
3
+ //= link rails_web_cache_manifest.js
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationController < ActionController::Base
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+ require_relative '../config/boot'
6
+ require 'rails/commands'
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../config/boot'
5
+ require 'rake'
6
+ Rake.application.run
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ # path to your application root.
8
+ APP_ROOT = File.expand_path('..', __dir__)
9
+
10
+ def system!(*args)
11
+ system(*args) || abort("\n== Command #{args} failed ==")
12
+ end
13
+
14
+ chdir APP_ROOT do
15
+ # This script is a starting point to setup your application.
16
+ # Add necessary setup steps to this file.
17
+
18
+ puts '== Installing dependencies =='
19
+ system! 'gem install bundler --conservative'
20
+ system('bundle check') || system!('bundle install')
21
+
22
+ # Install JavaScript dependencies if using Yarn
23
+ # system('bin/yarn')
24
+
25
+ # puts "\n== Copying sample files =="
26
+ # unless File.exist?('config/database.yml')
27
+ # cp 'config/database.yml.sample', 'config/database.yml'
28
+ # end
29
+
30
+ puts "\n== Preparing database =="
31
+ system! 'bin/rails db:setup'
32
+
33
+ puts "\n== Removing old logs and tempfiles =="
34
+ system! 'bin/rails log:clear tmp:clear'
35
+
36
+ puts "\n== Restarting application server =="
37
+ system! 'bin/rails restart'
38
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ # path to your application root.
8
+ APP_ROOT = File.expand_path('..', __dir__)
9
+
10
+ def system!(*args)
11
+ system(*args) || abort("\n== Command #{args} failed ==")
12
+ end
13
+
14
+ chdir APP_ROOT do
15
+ # This script is a way to update your development environment automatically.
16
+ # Add necessary update steps to this file.
17
+
18
+ puts '== Installing dependencies =='
19
+ system! 'gem install bundler --conservative'
20
+ system('bundle check') || system!('bundle install')
21
+
22
+ # Install JavaScript dependencies if using Yarn
23
+ # system('bin/yarn')
24
+
25
+ puts "\n== Updating database =="
26
+ system! 'bin/rails db:migrate'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ puts "\n== Restarting application server =="
32
+ system! 'bin/rails restart'
33
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_ROOT = File.expand_path('..', __dir__)
5
+ Dir.chdir(APP_ROOT) do
6
+ begin
7
+ exec 'yarnpkg', *ARGV
8
+ rescue Errno::ENOENT
9
+ warn 'Yarn executable was not detected in the system.'
10
+ warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
11
+ exit 1
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ require 'rails'
6
+ require 'action_controller/railtie'
7
+ require 'action_view/railtie'
8
+ require 'sprockets/railtie'
9
+
10
+ Bundler.require(*Rails.groups)
11
+ require 'rails_web_cache'
12
+
13
+ module Dummy
14
+ class Application < Rails::Application
15
+ # Initialize configuration defaults for originally generated Rails version.
16
+ config.load_defaults 5.2
17
+
18
+ # Settings in config/environments/* take precedence over those specified here.
19
+ # Application configuration can go into files in config/initializers
20
+ # -- all .rb files in that directory are automatically loaded after loading
21
+ # the framework and any gems in your application.
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
5
+
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
7
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load the Rails application.
4
+ require_relative 'application'
5
+
6
+ # Initialize the Rails application.
7
+ Rails.application.initialize!
@@ -0,0 +1,47 @@
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.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ # Run rails dev:cache to toggle caching.
17
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
18
+ config.action_controller.perform_caching = true
19
+
20
+ config.cache_store = :memory_store
21
+ config.public_file_server.headers = {
22
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23
+ }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+
27
+ config.cache_store = :null_store
28
+ end
29
+
30
+ # Print deprecation notices to the Rails logger.
31
+ config.active_support.deprecation = :log
32
+
33
+ # Debug mode disables concatenation and preprocessing of assets.
34
+ # This option may cause significant delays in view rendering with a large
35
+ # number of complex assets.
36
+ config.assets.debug = true
37
+
38
+ # Suppress logger output for asset requests.
39
+ config.assets.quiet = true
40
+
41
+ # Raises error for missing translations.
42
+ # config.action_view.raise_on_missing_translations = true
43
+
44
+ # Use an evented file watcher to asynchronously detect changes in source code,
45
+ # routes, locales, etc. This feature depends on the listen gem.
46
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
47
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Code is not reloaded between requests.
7
+ config.cache_classes = true
8
+
9
+ # Eager load code on boot. This eager loads most of Rails and
10
+ # your application in memory, allowing both threaded web servers
11
+ # and those relying on copy on write to perform better.
12
+ # Rake tasks automatically ignore this option for performance.
13
+ config.eager_load = true
14
+
15
+ # Full error reports are disabled and caching is turned on.
16
+ config.consider_all_requests_local = false
17
+ config.action_controller.perform_caching = true
18
+
19
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21
+ # config.require_master_key = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
26
+
27
+ # Compress CSS using a preprocessor.
28
+ # config.assets.css_compressor = :sass
29
+
30
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
31
+ config.assets.compile = false
32
+
33
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
34
+
35
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
36
+ # config.action_controller.asset_host = 'http://assets.example.com'
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
+ # Use the lowest log level to ensure availability of diagnostic information
46
+ # when problems arise.
47
+ config.log_level = :debug
48
+
49
+ # Prepend all log lines with the following tags.
50
+ config.log_tags = [:request_id]
51
+
52
+ # Use a different cache store in production.
53
+ # config.cache_store = :mem_cache_store
54
+
55
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
56
+ # the I18n.default_locale when a translation cannot be found).
57
+ config.i18n.fallbacks = true
58
+
59
+ # Send deprecation notices to registered listeners.
60
+ config.active_support.deprecation = :notify
61
+
62
+ # Use default logging formatter so that PID and timestamp are not suppressed.
63
+ config.log_formatter = ::Logger::Formatter.new
64
+
65
+ # Use a different logger for distributed setups.
66
+ # require 'syslog/logger'
67
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
68
+
69
+ if ENV['RAILS_LOG_TO_STDOUT'].present?
70
+ logger = ActiveSupport::Logger.new(STDOUT)
71
+ logger.formatter = config.log_formatter
72
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
73
+ end
74
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+
8
+ Rails.application.configure do
9
+ # Settings specified here will take precedence over those in config/application.rb.
10
+
11
+ config.cache_classes = false
12
+
13
+ # Do not eager load code on boot. This avoids loading your whole application
14
+ # just for the purpose of running a single test. If you are using a tool that
15
+ # preloads Rails for running tests, you may have to set it to true.
16
+ config.eager_load = false
17
+
18
+ # Configure public file server for tests with Cache-Control for performance.
19
+ config.public_file_server.enabled = true
20
+ config.public_file_server.headers = {
21
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
22
+ }
23
+
24
+ # Show full error reports and disable caching.
25
+ config.consider_all_requests_local = true
26
+ config.action_controller.perform_caching = false
27
+ config.cache_store = :memory_store
28
+
29
+ # Raise exceptions instead of rendering exception templates.
30
+ config.action_dispatch.show_exceptions = false
31
+
32
+ # Disable request forgery protection in test environment.
33
+ config.action_controller.allow_forgery_protection = false
34
+
35
+ # Print deprecation notices to the stderr.
36
+ config.active_support.deprecation = :stderr
37
+
38
+ # Raises error for missing translations.
39
+ # config.action_view.raise_on_missing_translations = true
40
+ end