Class: ActiveSupport::Callbacks::Filters::Before
- Defined in:
- activesupport/lib/active_support/callbacks.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#halted_lambda ⇒ Object
readonly
Returns the value of attribute halted_lambda.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#user_callback ⇒ Object
readonly
Returns the value of attribute user_callback.
-
#user_conditions ⇒ Object
readonly
Returns the value of attribute user_conditions.
Instance Method Summary collapse
- #apply(callback_sequence) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(user_callback, user_conditions, chain_config, filter, name) ⇒ Before
constructor
A new instance of Before.
Constructor Details
#initialize(user_callback, user_conditions, chain_config, filter, name) ⇒ Before
Returns a new instance of Before.
165 166 167 168 169 |
# File 'activesupport/lib/active_support/callbacks.rb', line 165 def initialize(user_callback, user_conditions, chain_config, filter, name) halted_lambda = chain_config[:terminator] @user_callback, @user_conditions, @halted_lambda, @filter, @name = user_callback, user_conditions, halted_lambda, filter, name freeze end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
170 171 172 |
# File 'activesupport/lib/active_support/callbacks.rb', line 170 def filter @filter end |
#halted_lambda ⇒ Object (readonly)
Returns the value of attribute halted_lambda.
170 171 172 |
# File 'activesupport/lib/active_support/callbacks.rb', line 170 def halted_lambda @halted_lambda end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
170 171 172 |
# File 'activesupport/lib/active_support/callbacks.rb', line 170 def name @name end |
#user_callback ⇒ Object (readonly)
Returns the value of attribute user_callback.
170 171 172 |
# File 'activesupport/lib/active_support/callbacks.rb', line 170 def user_callback @user_callback end |
#user_conditions ⇒ Object (readonly)
Returns the value of attribute user_conditions.
170 171 172 |
# File 'activesupport/lib/active_support/callbacks.rb', line 170 def user_conditions @user_conditions end |
Instance Method Details
#apply(callback_sequence) ⇒ Object
188 189 190 |
# File 'activesupport/lib/active_support/callbacks.rb', line 188 def apply(callback_sequence) callback_sequence.before(self) end |
#call(env) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'activesupport/lib/active_support/callbacks.rb', line 172 def call(env) target = env.target value = env.value halted = env.halted if !halted && user_conditions.all? { |c| c.call(target, value) } result_lambda = -> { user_callback.call target, value } env.halted = halted_lambda.call(target, result_lambda) if env.halted target.send :halted_callback_hook, filter, name end end env end |