object-filters 0.0.5 → 0.0.6

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -7,197 +7,195 @@ require 'active_support/callbacks'
7
7
  __PATH__ = Pathname.new(__FILE__)
8
8
  $:.unshift(__PATH__.dirname.to_s) unless $:.include?(__PATH__.dirname.to_s)
9
9
 
10
- module AbstractController
11
- module Callbacks
12
- extend ActiveSupport::Concern
10
+ module Filters
11
+ extend ActiveSupport::Concern
13
12
 
14
- # Uses ActiveSupport::Callbacks as the base functionality. For
15
- # more details on the whole callback system, read the documentation
16
- # for ActiveSupport::Callbacks.
17
- include ActiveSupport::Callbacks
13
+ # Uses ActiveSupport::Callbacks as the base functionality. For
14
+ # more details on the whole callback system, read the documentation
15
+ # for ActiveSupport::Callbacks.
16
+ include ActiveSupport::Callbacks
18
17
 
19
- included do
20
- define_callbacks :process_action, :terminator => "response_body", :skip_after_callbacks_if_terminated => true
21
- end
18
+ included do
19
+ define_callbacks :process_action, :terminator => "response_body", :skip_after_callbacks_if_terminated => true
20
+ end
22
21
 
23
- # Override AbstractController::Base's process_action to run the
24
- # process_action callbacks around the normal behavior.
25
- def process_action(*args)
26
- run_callbacks(:process_action) do
27
- super
28
- end
22
+ # Override AbstractController::Base's process_action to run the
23
+ # process_action callbacks around the normal behavior.
24
+ def process_action(*args)
25
+ run_callbacks(:process_action) do
26
+ super
29
27
  end
28
+ end
30
29
 
31
- module ClassMethods
32
- # If :only or :except are used, convert the options into the
33
- # :unless and :if options of ActiveSupport::Callbacks.
34
- # The basic idea is that :only => :index gets converted to
35
- # :if => proc {|c| c.action_name == "index" }.
36
- #
37
- # ==== Options
38
- # * <tt>only</tt> - The callback should be run only for this action
39
- # * <tt>except</tt> - The callback should be run for all actions except this action
40
- def _normalize_callback_options(options)
41
- if only = options[:only]
42
- only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
43
- options[:if] = Array(options[:if]) << only
44
- end
45
- if except = options[:except]
46
- except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
47
- options[:unless] = Array(options[:unless]) << except
48
- end
30
+ module ClassMethods
31
+ # If :only or :except are used, convert the options into the
32
+ # :unless and :if options of ActiveSupport::Callbacks.
33
+ # The basic idea is that :only => :index gets converted to
34
+ # :if => proc {|c| c.action_name == "index" }.
35
+ #
36
+ # ==== Options
37
+ # * <tt>only</tt> - The callback should be run only for this action
38
+ # * <tt>except</tt> - The callback should be run for all actions except this action
39
+ def _normalize_callback_options(options)
40
+ if only = options[:only]
41
+ only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ")
42
+ options[:if] = Array(options[:if]) << only
49
43
  end
50
-
51
- # Skip before, after, and around filters matching any of the names
52
- #
53
- # ==== Parameters
54
- # * <tt>names</tt> - A list of valid names that could be used for
55
- # callbacks. Note that skipping uses Ruby equality, so it's
56
- # impossible to skip a callback defined using an anonymous proc
57
- # using #skip_filter
58
- def skip_filter(*names)
59
- skip_before_filter(*names)
60
- skip_after_filter(*names)
61
- skip_around_filter(*names)
44
+ if except = options[:except]
45
+ except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ")
46
+ options[:unless] = Array(options[:unless]) << except
62
47
  end
48
+ end
63
49
 
64
- # Take callback names and an optional callback proc, normalize them,
65
- # then call the block with each callback. This allows us to abstract
66
- # the normalization across several methods that use it.
67
- #
68
- # ==== Parameters
69
- # * <tt>callbacks</tt> - An array of callbacks, with an optional
70
- # options hash as the last parameter.
71
- # * <tt>block</tt> - A proc that should be added to the callbacks.
72
- #
73
- # ==== Block Parameters
74
- # * <tt>name</tt> - The callback to be added
75
- # * <tt>options</tt> - A hash of options to be used when adding the callback
76
- def _insert_callbacks(callbacks, block = nil)
77
- options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
78
- _normalize_callback_options(options)
79
- callbacks.push(block) if block
80
- callbacks.each do |callback|
81
- yield callback, options
82
- end
83
- end
50
+ # Skip before, after, and around filters matching any of the names
51
+ #
52
+ # ==== Parameters
53
+ # * <tt>names</tt> - A list of valid names that could be used for
54
+ # callbacks. Note that skipping uses Ruby equality, so it's
55
+ # impossible to skip a callback defined using an anonymous proc
56
+ # using #skip_filter
57
+ def skip_filter(*names)
58
+ skip_before_filter(*names)
59
+ skip_after_filter(*names)
60
+ skip_around_filter(*names)
61
+ end
84
62
 
85
- ##
86
- # :method: before_filter
87
- #
88
- # :call-seq: before_filter(names, block)
89
- #
90
- # Append a before filter. See _insert_callbacks for parameter details.
91
-
92
- ##
93
- # :method: prepend_before_filter
94
- #
95
- # :call-seq: prepend_before_filter(names, block)
96
- #
97
- # Prepend a before filter. See _insert_callbacks for parameter details.
98
-
99
- ##
100
- # :method: skip_before_filter
101
- #
102
- # :call-seq: skip_before_filter(names)
103
- #
104
- # Skip a before filter. See _insert_callbacks for parameter details.
105
-
106
- ##
107
- # :method: append_before_filter
108
- #
109
- # :call-seq: append_before_filter(names, block)
110
- #
111
- # Append a before filter. See _insert_callbacks for parameter details.
112
-
113
- ##
114
- # :method: after_filter
115
- #
116
- # :call-seq: after_filter(names, block)
117
- #
118
- # Append an after filter. See _insert_callbacks for parameter details.
119
-
120
- ##
121
- # :method: prepend_after_filter
122
- #
123
- # :call-seq: prepend_after_filter(names, block)
124
- #
125
- # Prepend an after filter. See _insert_callbacks for parameter details.
126
-
127
- ##
128
- # :method: skip_after_filter
129
- #
130
- # :call-seq: skip_after_filter(names)
131
- #
132
- # Skip an after filter. See _insert_callbacks for parameter details.
133
-
134
- ##
135
- # :method: append_after_filter
136
- #
137
- # :call-seq: append_after_filter(names, block)
138
- #
139
- # Append an after filter. See _insert_callbacks for parameter details.
140
-
141
- ##
142
- # :method: around_filter
143
- #
144
- # :call-seq: around_filter(names, block)
145
- #
146
- # Append an around filter. See _insert_callbacks for parameter details.
147
-
148
- ##
149
- # :method: prepend_around_filter
150
- #
151
- # :call-seq: prepend_around_filter(names, block)
152
- #
153
- # Prepend an around filter. See _insert_callbacks for parameter details.
154
-
155
- ##
156
- # :method: skip_around_filter
157
- #
158
- # :call-seq: skip_around_filter(names)
159
- #
160
- # Skip an around filter. See _insert_callbacks for parameter details.
161
-
162
- ##
163
- # :method: append_around_filter
164
- #
165
- # :call-seq: append_around_filter(names, block)
166
- #
167
- # Append an around filter. See _insert_callbacks for parameter details.
168
-
169
- # set up before_filter, prepend_before_filter, skip_before_filter, etc.
170
- # for each of before, after, and around.
171
- [:before, :after, :around].each do |filter|
172
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
173
- # Append a before, after or around filter. See _insert_callbacks
174
- # for details on the allowed parameters.
175
- def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk)
176
- _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
177
- set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options)
178
- end # end
179
- end # end
180
-
181
- # Prepend a before, after or around filter. See _insert_callbacks
182
- # for details on the allowed parameters.
183
- def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk)
184
- _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
185
- set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
186
- end # end
187
- end # end
188
-
189
- # Skip a before, after or around filter. See _insert_callbacks
190
- # for details on the allowed parameters.
191
- def skip_#{filter}_filter(*names) # def skip_before_filter(*names)
192
- _insert_callbacks(names) do |name, options| # _insert_callbacks(names) do |name, options|
193
- skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options)
194
- end # end
195
- end # end
196
-
197
- # *_filter is the same as append_*_filter
198
- alias_method :append_#{filter}_filter, :#{filter}_filter # alias_method :append_before_filter, :before_filter
199
- RUBY_EVAL
63
+ # Take callback names and an optional callback proc, normalize them,
64
+ # then call the block with each callback. This allows us to abstract
65
+ # the normalization across several methods that use it.
66
+ #
67
+ # ==== Parameters
68
+ # * <tt>callbacks</tt> - An array of callbacks, with an optional
69
+ # options hash as the last parameter.
70
+ # * <tt>block</tt> - A proc that should be added to the callbacks.
71
+ #
72
+ # ==== Block Parameters
73
+ # * <tt>name</tt> - The callback to be added
74
+ # * <tt>options</tt> - A hash of options to be used when adding the callback
75
+ def _insert_callbacks(callbacks, block = nil)
76
+ options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
77
+ _normalize_callback_options(options)
78
+ callbacks.push(block) if block
79
+ callbacks.each do |callback|
80
+ yield callback, options
200
81
  end
201
82
  end
83
+
84
+ ##
85
+ # :method: before_filter
86
+ #
87
+ # :call-seq: before_filter(names, block)
88
+ #
89
+ # Append a before filter. See _insert_callbacks for parameter details.
90
+
91
+ ##
92
+ # :method: prepend_before_filter
93
+ #
94
+ # :call-seq: prepend_before_filter(names, block)
95
+ #
96
+ # Prepend a before filter. See _insert_callbacks for parameter details.
97
+
98
+ ##
99
+ # :method: skip_before_filter
100
+ #
101
+ # :call-seq: skip_before_filter(names)
102
+ #
103
+ # Skip a before filter. See _insert_callbacks for parameter details.
104
+
105
+ ##
106
+ # :method: append_before_filter
107
+ #
108
+ # :call-seq: append_before_filter(names, block)
109
+ #
110
+ # Append a before filter. See _insert_callbacks for parameter details.
111
+
112
+ ##
113
+ # :method: after_filter
114
+ #
115
+ # :call-seq: after_filter(names, block)
116
+ #
117
+ # Append an after filter. See _insert_callbacks for parameter details.
118
+
119
+ ##
120
+ # :method: prepend_after_filter
121
+ #
122
+ # :call-seq: prepend_after_filter(names, block)
123
+ #
124
+ # Prepend an after filter. See _insert_callbacks for parameter details.
125
+
126
+ ##
127
+ # :method: skip_after_filter
128
+ #
129
+ # :call-seq: skip_after_filter(names)
130
+ #
131
+ # Skip an after filter. See _insert_callbacks for parameter details.
132
+
133
+ ##
134
+ # :method: append_after_filter
135
+ #
136
+ # :call-seq: append_after_filter(names, block)
137
+ #
138
+ # Append an after filter. See _insert_callbacks for parameter details.
139
+
140
+ ##
141
+ # :method: around_filter
142
+ #
143
+ # :call-seq: around_filter(names, block)
144
+ #
145
+ # Append an around filter. See _insert_callbacks for parameter details.
146
+
147
+ ##
148
+ # :method: prepend_around_filter
149
+ #
150
+ # :call-seq: prepend_around_filter(names, block)
151
+ #
152
+ # Prepend an around filter. See _insert_callbacks for parameter details.
153
+
154
+ ##
155
+ # :method: skip_around_filter
156
+ #
157
+ # :call-seq: skip_around_filter(names)
158
+ #
159
+ # Skip an around filter. See _insert_callbacks for parameter details.
160
+
161
+ ##
162
+ # :method: append_around_filter
163
+ #
164
+ # :call-seq: append_around_filter(names, block)
165
+ #
166
+ # Append an around filter. See _insert_callbacks for parameter details.
167
+
168
+ # set up before_filter, prepend_before_filter, skip_before_filter, etc.
169
+ # for each of before, after, and around.
170
+ [:before, :after, :around].each do |filter|
171
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
172
+ # Append a before, after or around filter. See _insert_callbacks
173
+ # for details on the allowed parameters.
174
+ def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk)
175
+ _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
176
+ set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options)
177
+ end # end
178
+ end # end
179
+
180
+ # Prepend a before, after or around filter. See _insert_callbacks
181
+ # for details on the allowed parameters.
182
+ def prepend_#{filter}_filter(*names, &blk) # def prepend_before_filter(*names, &blk)
183
+ _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
184
+ set_callback(:process_action, :#{filter}, name, options.merge(:prepend => true)) # set_callback(:process_action, :before, name, options.merge(:prepend => true))
185
+ end # end
186
+ end # end
187
+
188
+ # Skip a before, after or around filter. See _insert_callbacks
189
+ # for details on the allowed parameters.
190
+ def skip_#{filter}_filter(*names) # def skip_before_filter(*names)
191
+ _insert_callbacks(names) do |name, options| # _insert_callbacks(names) do |name, options|
192
+ skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options)
193
+ end # end
194
+ end # end
195
+
196
+ # *_filter is the same as append_*_filter
197
+ alias_method :append_#{filter}_filter, :#{filter}_filter # alias_method :append_before_filter, :before_filter
198
+ RUBY_EVAL
199
+ end
202
200
  end
203
201
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "object-filters"
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Scott Lewis"]
9
9
  s.date = "2012-10-08"
10
- s.description = "This gem provides ActionController::Filters for normal applications."
11
- s.email = ["ryan@rynet.us"]
12
- s.files = [".gitignore", "Gemfile", "Rakefile", "VERSION", "filters.gemspec", "lib/filters.rb", "spec/filters_spec.rb", "spec/spec_helper.rb"]
13
- s.homepage = "http://rubygems.org/gems/filters"
10
+ s.description = "This gem provides ActionController::Filters for your custom classes."
11
+ s.email = "ryan@rynet.us"
12
+ s.files = [".gitignore", "Gemfile", "Rakefile", "VERSION", "object-filters.gemspec", "lib/filters.rb", "spec/filters_spec.rb", "spec/spec_helper.rb"]
13
+ s.homepage = "http://rubygems.org/gems/object-filters"
14
14
  s.post_install_message = "This is a placeholder gem... for now. Check back in a few versions!"
15
15
  s.require_paths = ["lib"]
16
16
  s.rubygems_version = "1.8.24"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object-filters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,9 +43,8 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3'
46
- description: This gem provides ActionController::Filters for normal applications.
47
- email:
48
- - ryan@rynet.us
46
+ description: This gem provides ActionController::Filters for your custom classes.
47
+ email: ryan@rynet.us
49
48
  executables: []
50
49
  extensions: []
51
50
  extra_rdoc_files: []
@@ -54,11 +53,11 @@ files:
54
53
  - Gemfile
55
54
  - Rakefile
56
55
  - VERSION
57
- - filters.gemspec
56
+ - object-filters.gemspec
58
57
  - lib/filters.rb
59
58
  - spec/filters_spec.rb
60
59
  - spec/spec_helper.rb
61
- homepage: http://rubygems.org/gems/filters
60
+ homepage: http://rubygems.org/gems/object-filters
62
61
  licenses: []
63
62
  post_install_message: This is a placeholder gem... for now. Check back in a few versions!
64
63
  rdoc_options: []