Class: ActiveSupport::Callbacks::Callback
- Defined in:
- lib/active_support/callbacks.rb
Overview
:nodoc:#
Constant Summary collapse
- @@_callback_sequence =
0
Instance Attribute Summary collapse
-
#chain ⇒ Object
Returns the value of attribute chain.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
-
#raw_filter ⇒ Object
Returns the value of attribute raw_filter.
Instance Method Summary collapse
- #_update_filter(filter_options, new_options) ⇒ Object
-
#apply(code) ⇒ Object
Wraps code with filter.
- #clone(chain, klass) ⇒ Object
- #deprecate_per_key_option(options) ⇒ Object
- #duplicates?(other) ⇒ Boolean
-
#initialize(chain, filter, kind, options, klass) ⇒ Callback
constructor
A new instance of Callback.
- #matches?(_kind, _filter) ⇒ Boolean
- #name ⇒ Object
- #next_id ⇒ Object
- #normalize_options!(options) ⇒ Object
- #recompile!(_options) ⇒ Object
Constructor Details
#initialize(chain, filter, kind, options, klass) ⇒ Callback
Returns a new instance of Callback.
96 97 98 99 100 101 102 103 104 |
# File 'lib/active_support/callbacks.rb', line 96 def initialize(chain, filter, kind, , klass) @chain, @kind, @klass = chain, kind, klass deprecate_per_key_option() () @raw_filter, @options = filter, @filter = _compile_filter(filter) end |
Instance Attribute Details
#chain ⇒ Object
Returns the value of attribute chain.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def chain @chain end |
#filter ⇒ Object
Returns the value of attribute filter.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def filter @filter end |
#kind ⇒ Object
Returns the value of attribute kind.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def kind @kind end |
#klass ⇒ Object
Returns the value of attribute klass.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def @options end |
#raw_filter ⇒ Object
Returns the value of attribute raw_filter.
94 95 96 |
# File 'lib/active_support/callbacks.rb', line 94 def raw_filter @raw_filter end |
Instance Method Details
#_update_filter(filter_options, new_options) ⇒ Object
143 144 145 146 |
# File 'lib/active_support/callbacks.rb', line 143 def _update_filter(, ) [:if].concat(Array([:unless])) if .key?(:unless) [:unless].concat(Array([:if])) if .key?(:if) end |
#apply(code) ⇒ Object
Wraps code with filter
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/active_support/callbacks.rb', line 156 def apply(code) case @kind when :before <<-RUBY_EVAL if !halted && #{@compiled_options} # This double assignment is to prevent warnings in 1.9.3 as # the `result` variable is not always used except if the # terminator code refers to it. result = result = #{@filter} halted = (#{chain.config[:terminator]}) if halted halted_callback_hook(#{@raw_filter.inspect.inspect}) end end #{code} RUBY_EVAL when :after <<-RUBY_EVAL #{code} if #{!chain.config[:skip_after_callbacks_if_terminated] || "!halted"} && #{@compiled_options} #{@filter} end RUBY_EVAL when :around name = define_conditional_callback <<-RUBY_EVAL #{name}(halted) do #{code} value end RUBY_EVAL end end |
#clone(chain, klass) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/active_support/callbacks.rb', line 112 def clone(chain, klass) obj = super() obj.chain = chain obj.klass = klass obj. = @options.dup obj.[:if] = @options[:if].dup obj.[:unless] = @options[:unless].dup obj end |
#deprecate_per_key_option(options) ⇒ Object
106 107 108 109 110 |
# File 'lib/active_support/callbacks.rb', line 106 def deprecate_per_key_option() if [:per_key] raise NotImplementedError, ":per_key option is no longer supported. Use generic :if and :unless options instead." end end |
#duplicates?(other) ⇒ Boolean
139 140 141 |
# File 'lib/active_support/callbacks.rb', line 139 def duplicates?(other) matches?(other.kind, other.filter) end |
#matches?(_kind, _filter) ⇒ Boolean
135 136 137 |
# File 'lib/active_support/callbacks.rb', line 135 def matches?(_kind, _filter) @kind == _kind && @filter == _filter end |
#name ⇒ Object
127 128 129 |
# File 'lib/active_support/callbacks.rb', line 127 def name chain.name end |
#next_id ⇒ Object
131 132 133 |
# File 'lib/active_support/callbacks.rb', line 131 def next_id @@_callback_sequence += 1 end |
#normalize_options!(options) ⇒ Object
122 123 124 125 |
# File 'lib/active_support/callbacks.rb', line 122 def () [:if] = Array([:if]) [:unless] = Array([:unless]) end |
#recompile!(_options) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/active_support/callbacks.rb', line 148 def recompile!() deprecate_per_key_option() _update_filter(self., ) end |