format_restricter_rails 1.1.0 → 1.2.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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +10 -27
- data/CHANGELOG.md +6 -1
- data/Gemfile +4 -0
- data/lib/format_restricter_rails/includes.rb +6 -3
- data/lib/format_restricter_rails/railtie.rb +3 -30
- data/lib/format_restricter_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f2bae3923b56bbc18ead2cf5fad9c1e1a03edeaaa30eb6ba111e9d1428ce96a
|
4
|
+
data.tar.gz: e6cc8b95986088cdf06078dbf6820b7a1772f257c23ca1095695e2d60ac6ad9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f209f31a8803d9d20d61a87b81111991cfb075464a490853a60cb24216dbe2358063dd09e1b9c032805dad81c71d6aaa69201744d2cd0e8359e04716a85d6d7a
|
7
|
+
data.tar.gz: 25fccc5bd94268c62f1c9d369ffb590e9c04e79db93ba6ea846e5e1843c93df24644f82e246eff496e15fa8ae993d1cfbb4bf8806b0967f641f10d05b69ea8ba
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,31 +1,14 @@
|
|
1
|
-
|
2
|
-
Exclude:
|
3
|
-
- spec/dummy/db/schema.rb
|
1
|
+
# DO NOT MODIFY THIS FILE unless you want to deviate from the rubocop_plus ruleset.
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
# This file defines the settings used by rubocop when it runs. You would normally add your customizations directly to this
|
4
|
+
# file, but this file has been pre configured to read settings out of the rubocop_plus gem instead.
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
# Tell rubocop to load its settings from the rubocop_plus gem.
|
7
|
+
inherit_gem:
|
8
|
+
rubocop_plus: config/rubocop.yml
|
10
9
|
|
11
|
-
|
12
|
-
Enabled:
|
10
|
+
Rails:
|
11
|
+
Enabled: true
|
13
12
|
|
14
|
-
|
15
|
-
|
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/**/*
|
13
|
+
# Place custom settings below this comment. All customizations will OVERRIDE rubocop_plus rules. rubocop_plus & rubocop
|
14
|
+
# do not attempt to merge these settings with their defaults. Long term changes should be ported to the rubocop_plus gem.
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.2.0 (Jan 18, 2018)
|
4
|
+
|
5
|
+
1. Use the `to_prepare` hook to simplify the implementation. (Issue #14)
|
6
|
+
1. Add the rubocop_plus gem and cleanup internal code. (Issue #16)
|
7
|
+
|
3
8
|
## 1.1.0 (Jan 08, 2018)
|
4
9
|
|
5
10
|
1. Add automated tests. (Issue #4)
|
@@ -8,7 +13,7 @@
|
|
8
13
|
|
9
14
|
## 1.0.1 (May 11, 2016)
|
10
15
|
|
11
|
-
1.
|
16
|
+
1. Fix formats not being blocked when when `only:` or `except:` are not specified (Issue #1)
|
12
17
|
|
13
18
|
## 1.0.0 (May 11, 2016)
|
14
19
|
|
data/Gemfile
CHANGED
@@ -3,6 +3,10 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in format_restricter_rails.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
group :development do
|
7
|
+
gem 'rubocop_plus', "~> 1.0", require: false
|
8
|
+
end
|
9
|
+
|
6
10
|
group :development, :test do
|
7
11
|
gem 'bootsnap', require: false
|
8
12
|
gem 'puma', '~> 3.7'
|
@@ -1,19 +1,22 @@
|
|
1
1
|
module FormatRestricterRails
|
2
|
+
# Create a wrapping module so we can expose class methods into the host controllers.
|
2
3
|
module Includes
|
3
4
|
def self.included(base)
|
4
5
|
base.extend(ClassMethods)
|
5
|
-
|
6
|
-
|
7
|
-
end
|
6
|
+
# This is one way to mark the register_before_action method as private in a module.
|
7
|
+
base.instance_eval { private_class_method :register_before_action }
|
8
8
|
end
|
9
9
|
|
10
|
+
# Define the methods that can be called by host controllers.
|
10
11
|
module ClassMethods
|
12
|
+
# This is the main API that host controllers will call at the top the controller.
|
11
13
|
def restrict_formats_to(*args)
|
12
14
|
options = args.extract_options!
|
13
15
|
allowed_formats = args.collect(&:to_sym)
|
14
16
|
register_before_action(options, allowed_formats)
|
15
17
|
end
|
16
18
|
|
19
|
+
# This method is turned into a private method above.
|
17
20
|
def register_before_action(options, allowed_formats)
|
18
21
|
before_action(options) do |_controller|
|
19
22
|
render nothing: true, status: 406 unless allowed_formats.include?(request.format.symbol)
|
@@ -1,35 +1,8 @@
|
|
1
1
|
module FormatRestricterRails
|
2
|
-
|
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
|
-
|
2
|
+
# This Railtie exposes the format_resticter_rails API to the host application controllers.
|
14
3
|
class Railtie < Rails::Railtie
|
15
|
-
|
16
|
-
|
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
|
4
|
+
config.to_prepare do
|
5
|
+
ApplicationController.include FormatRestricterRails::Includes
|
33
6
|
end
|
34
7
|
end
|
35
8
|
end
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- roberts1000
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|