format_restricter_rails 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4972618603956be5371074aff97c5789b6aec167
4
- data.tar.gz: 627c68d3c620600806fd4553cb310dfa67ed3845
2
+ SHA256:
3
+ metadata.gz: f580e752ae0d6e79c2f5cf704384edeeffeba8f954c4ad0e19c88b3d90926d0f
4
+ data.tar.gz: 1874e0d2575f44e105a877c332765da832497287631507cfa17c3876c517d000
5
5
  SHA512:
6
- metadata.gz: 35317de7978900af29f0452fa8eda71db806ab3a65b817fe931da560a692e98ee4649b7c77eaabae7be0c0f0d8f342b841c748d9bc32d389adfd8dae11cc31a0
7
- data.tar.gz: aed2f149cbb0e918fa32a80a571867b93f66e9b58f724cb7b2b441e63975f38110f932b50251e4ac091f6c799702df1d1f53ae6b13be56934d43b1174dcd587c
6
+ metadata.gz: 918da1d938efb0809aa1339686d2536a63ae26c7ef8aa1226b217152192092c6b0af2b7877960c9102f14ee2844441332a1ea3a29ee80612253ce537f9eca31a
7
+ data.tar.gz: 3b79d1f075da8e17840ae68edbfde09da167de62312c6fde473da00d2f9b3f254d02899e15fde02c5754dfa2dbb61acaa46b922f36cd8d611b37933c4e980d10
data/.gitignore CHANGED
@@ -7,3 +7,9 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ /spec/dummy/db/*.sqlite3
12
+ /spec/dummy/db/*.sqlite3-journal
13
+ /spec/dummy/log/*.log
14
+ /spec/dummy/tmp/
15
+ /spec/dummy/.sass-cache
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
+ --require rails_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/dummy/db/schema.rb
4
+
5
+ Style/StringLiterals:
6
+ Enabled: false
7
+
8
+ Style/SymbolArray:
9
+ Enabled: false
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ Style/EmptyMethod:
15
+ Enabled: false
16
+
17
+ Style/StderrPuts:
18
+ Exclude:
19
+ - spec/dummy/bin/yarn
20
+
21
+ Style/MixinUsage:
22
+ Exclude:
23
+ - spec/dummy/bin/setup
24
+ - spec/dummy/bin/update
25
+
26
+ Metrics/LineLength:
27
+ Max: 130
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - spec/**/*
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0 (Jan 08, 2018)
4
+
5
+ 1. Add automated tests. (Issue #4)
6
+ 1. Configure travis CI to use cached versions of gems. (Issue #8)
7
+ 1. Correct rubocop issues. (Issue #11)
8
+
3
9
  ## 1.0.1 (May 11, 2016)
4
10
 
5
11
  1. (Fix) Formats not being blocked when when `only:` or `except:` are not specified (Issue #1)
6
12
 
7
13
  ## 1.0.0 (May 11, 2016)
8
14
 
9
- 1. Initial Release
15
+ 1. Initial Release
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in format_restricter_rails.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'bootsnap', require: false
8
+ gem 'puma', '~> 3.7'
9
+ end
File without changes
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # format_restricter_rails
2
2
 
3
- This gem provides a simple way to block your Rails controller actions from trying to process unsupported formats. Without this, you'll eventually start seeing the following errors on your production site:
3
+ This gem provides a simple way to block your Rails controller actions from processing unsupported formats. Without this, you'll eventually start seeing the following errors on your production site:
4
4
 
5
5
  ````
6
6
  ActionView::MissingTemplate (Missing template tasks/index, application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}
7
7
  ````
8
8
 
9
- Why are you getting these errors? Because you designed your sweet little controller action to only process html requests and someone decided to send it a .json request. Rails happily obliged, processed the action and failed when it couldn't find a corresponding json template to render.
9
+ Why are you getting these errors? Because you designed your snazzy controller action to only process html requests and someone decided to send it a .json request. Rails happily obliged, processed the action and failed when it couldn't find a corresponding json template to render.
10
10
 
11
- When this happens, you may think to start defining `respond_to` calls in your actions. Once you realize that's going to explode your code base, you'll probably try to call `respond_to :html` at the top of your controller class in hopes that will help. Sadly, it won't; and that's where this gem comes in. It provides a single controller class method, called `restrict_formats_to` that you can add to your controller to declare the formats that it is allowed to process. When unallowed formats are requested, halts execution and returns an **HTTP Error 406 Not acceptable**.
11
+ When this happens, you may start defining `respond_to` calls in your actions. Once you realize that's going to explode your code base, you'll probably try to call `respond_to :html` at the top of your controller class in hopes that it will help. Sadly, it won't; and that's where this gem comes in. It provides a single controller class method called `restrict_formats_to` that does exactly what you want. When unallowed formats are requested, the controller will halt execution and return **HTTP Error 406 Not acceptable**.
12
12
 
13
13
  ## Versioning Scheme
14
14
 
@@ -16,8 +16,7 @@ This gem uses [semver](http:/semver.org).
16
16
 
17
17
  ## Supported Rails Versions
18
18
 
19
- Currently tested with Rails 4+.
20
- Not tested in Rails 5 yet.
19
+ Rails 4+.
21
20
 
22
21
  ## Installation
23
22
 
@@ -33,9 +32,9 @@ And then execute:
33
32
 
34
33
  ## Usage
35
34
 
36
- The `restrict_formats_to` is just a wrapper around a `before_action` helper and you can use the standard `only:` and `except:` options.
35
+ Add `restrict_formats_to` to the top of a controller to restrict all actions in the controller to the specified format(s).
37
36
 
38
- #### Example 1: Restrict all actions
37
+ #### Example 1: Restrict all actions
39
38
 
40
39
  ````ruby
41
40
  class MySnazzyController < ApplicationController
@@ -45,22 +44,42 @@ class MySnazzyController < ApplicationController
45
44
  end
46
45
 
47
46
  def my_action_2
48
- end
47
+ end
49
48
  end
50
49
  ````
51
50
 
52
- #### Example 2: Mix and match
51
+ You can also use `only:` and `except:` options to target specific actions.
52
+
53
+
54
+ #### Example 2: Using the `only:` option
53
55
 
54
56
  ````ruby
55
57
  class MySnazzyController < ApplicationController
56
58
  restrict_formats_to :html, only: :my_action_1
57
- restrict_formats_to :json, only: :my_action_2
59
+ restrict_formats_to :json, only: [:my_action_2, :my_action_3]
60
+
61
+ def my_action_1
62
+ end
63
+
64
+ def my_action_2
65
+ end
66
+
67
+ def my_action_3
68
+ end
69
+ end
70
+ ````
71
+
72
+ #### Example 2: Using the `except:` Option
73
+
74
+ ````ruby
75
+ class MySnazzyController < ApplicationController
76
+ restrict_formats_to :html, except: :my_action_1
58
77
 
59
78
  def my_action_1
60
79
  end
61
80
 
62
81
  def my_action_2
63
- end
82
+ end
64
83
  end
65
84
  ````
66
85
 
data/Rakefile CHANGED
@@ -1,11 +1,21 @@
1
- require "bundler/gem_tasks"
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+ load 'rails/tasks/statistics.rake'
10
+ Bundler::GemHelper.install_tasks
11
+
2
12
  require "rspec/core/rake_task"
3
13
 
4
14
  RSpec::Core::RakeTask.new(:spec)
5
15
 
6
- task :default => :spec
16
+ task default: :spec
7
17
 
8
18
  task :console do
9
19
  exec "pry -r format_restricter_rails -I ./lib"
10
- #exec "irb -r format_restricter_rails -I ./lib"
11
- end
20
+ # exec "irb -r format_restricter_rails -I ./lib"
21
+ end
data/bin/dummy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir.chdir('spec/dummy') do
4
+ `rails s -b 0.0.0.0`
5
+ end
data/bin/rails ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/format_restricter_rails/engine', __FILE__)
7
+ APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'rails/all'
14
+ require 'rails/engine/commands'
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'format_restricter_rails/version'
@@ -6,11 +5,11 @@ require 'format_restricter_rails/version'
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "format_restricter_rails"
8
7
  spec.version = FormatRestricterRails::VERSION
9
- spec.authors = ["Roberts"]
8
+ spec.authors = ["roberts1000"]
10
9
  spec.email = ["roberts@corlewsolutions.com"]
11
10
 
12
- spec.summary = "Restrict the formats that your Rails controller actions are allowed to process"
13
- spec.description = "Restrict the formats that your Rails controller actions are allowed to process"
11
+ spec.summary = "A Rails Engine that prevents Rails controllers from processing undesired formats."
12
+ spec.description = "A Rails Engine that restricts the formats that your Rails controller actions are allowed to process."
14
13
  spec.homepage = "https://github.com/corlewsolutions/format_restricter_rails"
15
14
  spec.license = "MIT"
16
15
 
@@ -19,10 +18,12 @@ Gem::Specification.new do |spec|
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
19
  spec.require_paths = ["lib"]
21
20
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.4"
25
- spec.add_development_dependency "pry", "~> 0.10.1"
21
+ spec.add_development_dependency "bundler", "~> 1.16"
22
+ spec.add_development_dependency "pry", "~> 0.11.3"
23
+ spec.add_development_dependency "rake", "~> 12.0"
24
+ spec.add_development_dependency "rspec-rails", "~> 3.7.2"
25
+ spec.add_development_dependency "sass-rails", "~> 5.0"
26
+ spec.add_development_dependency "sqlite3", "~> 1.3.11"
26
27
 
27
28
  spec.add_dependency "rails", ">= 4"
28
29
  end
@@ -1,4 +1,4 @@
1
- module FormatRestricterRails
2
- class Engine < ::Rails::Engine
3
- end
4
- end
1
+ module FormatRestricterRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -1,27 +1,24 @@
1
- module FormatRestricterRails
2
- module Includes
3
-
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- base.instance_eval do
7
- private_class_method :register_before_action
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def restrict_formats_to(*args)
13
- options = args.extract_options!
14
- allowed_formats = args.collect {|e| e.to_sym}
15
- register_before_action(options, allowed_formats)
16
- end
17
-
18
- def register_before_action(options, allowed_formats)
19
- before_action(options) do |controller|
20
- unless allowed_formats.include?(request.format.symbol)
21
- render nothing: true, status: 406
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
1
+ module FormatRestricterRails
2
+ module Includes
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ base.instance_eval do
6
+ private_class_method :register_before_action
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def restrict_formats_to(*args)
12
+ options = args.extract_options!
13
+ allowed_formats = args.collect(&:to_sym)
14
+ register_before_action(options, allowed_formats)
15
+ end
16
+
17
+ def register_before_action(options, allowed_formats)
18
+ before_action(options) do |_controller|
19
+ render nothing: true, status: 406 unless allowed_formats.include?(request.format.symbol)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,38 +1,35 @@
1
- module FormatRestricterRails
2
-
3
- def self.include_modules_into_host_app
4
- ApplicationController.include FormatRestricterRails::Includes
5
- end
6
-
7
- def self.was_eager_loaded?
8
- @was_eager_loaded ||= false
9
- end
10
-
11
- def self.was_eager_loaded=value
12
- @was_eager_loaded = value
13
- end
14
-
15
- class Railtie < Rails::Railtie
16
- # This code will be run before Rails eager loads all of the application code. This method will typically only fire
17
- # in production-like environments, however, it could happen in development if the necessary config options are set for the
18
- # development.rb.
19
- config.before_eager_load do
20
- FormatRestricterRails.include_modules_into_host_app
21
- FormatRestricterRails.was_eager_loaded = true
22
- end
23
-
24
- config.after_initialize do
25
- # Don't rerun some setup code if eager loading occured. It can result in weird things happening.
26
- unless FormatRestricterRails.was_eager_loaded?
27
- FormatRestricterRails.include_modules_into_host_app
28
- end
29
-
30
- # Make sure the code is reloaded in development
31
- if Rails.env.development?
32
- ActionDispatch::Callbacks.before do
33
- FormatRestricterRails.include_modules_into_host_app
34
- end
35
- end
36
- end
37
- end
38
- end
1
+ module FormatRestricterRails
2
+ def self.include_modules_into_host_app
3
+ ApplicationController.include FormatRestricterRails::Includes
4
+ end
5
+
6
+ def self.was_eager_loaded?
7
+ @was_eager_loaded ||= false
8
+ end
9
+
10
+ def self.was_eager_loaded=(value)
11
+ @was_eager_loaded = value
12
+ end
13
+
14
+ class Railtie < Rails::Railtie
15
+ # This code will be run before Rails eager loads all of the application code. This method will typically only fire
16
+ # in production-like environments, however, it could happen in development if the necessary config options are set for the
17
+ # development.rb.
18
+ config.before_eager_load do
19
+ FormatRestricterRails.include_modules_into_host_app
20
+ FormatRestricterRails.was_eager_loaded = true
21
+ end
22
+
23
+ config.after_initialize do
24
+ # Don't rerun some setup code if eager loading occured. It can result in weird things happening.
25
+ FormatRestricterRails.include_modules_into_host_app unless FormatRestricterRails.was_eager_loaded?
26
+
27
+ # Make sure the code is reloaded in development
28
+ if Rails.env.development?
29
+ ActionDispatch::Callbacks.before do
30
+ FormatRestricterRails.include_modules_into_host_app
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module FormatRestricterRails
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0".freeze
3
3
  end
@@ -7,7 +7,9 @@ require "format_restricter_rails/railtie"
7
7
  # Setup pry for development when running "rake console". Guard against load
8
8
  # errors in production (since pry is only loaded as a DEVELOPMENT dependency
9
9
  # in the .gemspec)
10
+ # rubocop:disable Lint/HandleExceptions
10
11
  begin
11
12
  require "pry"
12
13
  rescue LoadError
13
14
  end
15
+ # rubocop:enable Lint/HandleExceptions
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_restricter_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Roberts
7
+ - roberts1000
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,56 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '1.16'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.11.3
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.0'
47
+ version: '12.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: '12.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rspec
56
+ name: rspec-rails
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.4'
61
+ version: 3.7.2
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.4'
68
+ version: 3.7.2
55
69
  - !ruby/object:Gem::Dependency
56
- name: pry
70
+ name: sass-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: 0.10.1
89
+ version: 1.3.11
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: 0.10.1
96
+ version: 1.3.11
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rails
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +108,8 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '4'
83
- description: Restrict the formats that your Rails controller actions are allowed to
84
- process
111
+ description: A Rails Engine that restricts the formats that your Rails controller
112
+ actions are allowed to process.
85
113
  email:
86
114
  - roberts@corlewsolutions.com
87
115
  executables: []
@@ -90,20 +118,23 @@ extra_rdoc_files: []
90
118
  files:
91
119
  - ".gitignore"
92
120
  - ".rspec"
121
+ - ".rubocop.yml"
93
122
  - ".travis.yml"
94
123
  - CHANGELOG.md
95
124
  - Gemfile
96
- - LICENSE.txt
125
+ - LICENSE.md
97
126
  - README.md
98
127
  - Rakefile
99
128
  - bin/console
129
+ - bin/dummy
130
+ - bin/rails
100
131
  - bin/setup
132
+ - format_restricter_rails.gemspec
101
133
  - lib/format_restricter_rails.rb
102
134
  - lib/format_restricter_rails/engine.rb
103
135
  - lib/format_restricter_rails/includes.rb
104
136
  - lib/format_restricter_rails/railtie.rb
105
137
  - lib/format_restricter_rails/version.rb
106
- - respond_to_by_controller.gemspec
107
138
  homepage: https://github.com/corlewsolutions/format_restricter_rails
108
139
  licenses:
109
140
  - MIT
@@ -124,8 +155,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
155
  version: '0'
125
156
  requirements: []
126
157
  rubyforge_project:
127
- rubygems_version: 2.6.4
158
+ rubygems_version: 2.7.4
128
159
  signing_key:
129
160
  specification_version: 4
130
- summary: Restrict the formats that your Rails controller actions are allowed to process
161
+ summary: A Rails Engine that prevents Rails controllers from processing undesired
162
+ formats.
131
163
  test_files: []