force_format 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/force_format.gemspec +1 -0
- data/lib/force_format/controller_access.rb +20 -26
- data/lib/force_format/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a968ff510d11c69b4429c7f611873c9329e0d3dd
|
4
|
+
data.tar.gz: e41c0108cdb7b26af2622c7aa1cac7ad144c84c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885860ffa29446ae06b1ca60119f645777d62b669649129e127e9f8bf761ade6def5c6453670778805c618133d4608c5bfa08258dc4565f6825c3e729afafe5a
|
7
|
+
data.tar.gz: 1e1f4969071e189f20fa6c325ff96aa900c455cab5dc0c3b53c35a27c3b627ffdf0918c15c4f086bce90506499e2d76ea6fbc5b4b2f12b31460f2b010de8367d
|
data/force_format.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rspec-rails', '~> 2.0'
|
24
24
|
spec.add_development_dependency 'shoulda-matchers', '~> 2.4'
|
25
25
|
spec.add_development_dependency "sqlite3"
|
26
|
+
spec.add_development_dependency "pry"
|
26
27
|
|
27
28
|
spec.add_dependency "rails", "~> 3.2"
|
28
29
|
end
|
@@ -2,44 +2,38 @@ require_relative "errors"
|
|
2
2
|
|
3
3
|
module ControllerAccess
|
4
4
|
extend ActiveSupport::Concern
|
5
|
+
FORCE_FORMAT_TYPES = [:html, :js, :json, :pdf, :csv, :zip, :xml]
|
6
|
+
FORCE_FORMAT_DEFAULT_TYPES = [:html]
|
5
7
|
|
6
8
|
module ClassMethods
|
7
9
|
include ForceFormat::Errors
|
8
|
-
FORCE_FORMAT_TYPES = [:html, :js, :json, :pdf, :csv, :zip, :xml]
|
9
|
-
FORCE_FORMAT_DEFAULT_TYPES = [:html]
|
10
10
|
|
11
11
|
def force_format_filter(opts={})
|
12
|
-
|
13
|
-
|
14
|
-
unsupported = forced_formats - FORCE_FORMAT_TYPES
|
15
|
-
raise UnsupportedFormatsError.new("There is no support for #{unsupported} format") if unsupported.any?
|
16
|
-
|
17
|
-
self.send(:before_filter, opts.slice(:only, :except, :if, :unless)) do |controller|
|
18
|
-
return if controller.instance_variable_get("@_skip_force_format_filter") == true
|
19
|
-
format = controller.request.format
|
20
|
-
unless forced_formats.include?(format.try(:to_sym))
|
21
|
-
raise ActionController::RoutingError, "Format '#{format}' not supported for #{request.path.inspect}"
|
22
|
-
end
|
23
|
-
end
|
12
|
+
send(:before_filter, :force_format_filter_method, opts.slice(:only, :except, :if, :unless, :for))
|
24
13
|
end
|
25
14
|
|
26
15
|
def skip_force_format_filter(opts={})
|
27
|
-
|
28
|
-
controller.instance_variable_set("@_skip_force_format_filter", true)
|
29
|
-
end
|
16
|
+
send(:skip_before_filter, :force_format_filter_method, opts.slice(:only, :except, :if, :unless))
|
30
17
|
end
|
31
18
|
|
32
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
23
|
+
def force_format_filter_method
|
24
|
+
force_formats = force_format_extract_options_from_filter_chain
|
25
|
+
unsupported = force_formats - FORCE_FORMAT_TYPES
|
26
|
+
raise UnsupportedFormatsError.new("There is no support for #{unsupported} format") if unsupported.any?
|
27
|
+
format = request.format
|
28
|
+
unless force_formats.include?(format.try(:to_sym))
|
29
|
+
raise ActionController::RoutingError, "Format '#{format}' not supported for #{request.path.inspect}"
|
42
30
|
end
|
31
|
+
end
|
43
32
|
|
33
|
+
def force_format_extract_options_from_filter_chain
|
34
|
+
filter = self._process_action_callbacks.find { |f| f.filter == :force_format_filter_method }
|
35
|
+
force_formats = filter.options[:for]
|
36
|
+
force_formats.is_a?(Array) ? force_formats : (force_formats.is_a?(Symbol) ? [force_formats] : FORCE_FORMAT_DEFAULT_TYPES)
|
44
37
|
end
|
38
|
+
|
45
39
|
end
|
data/lib/force_format/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: force_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- |
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: pry
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: rails
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|