Class: ActiveSupport::Callbacks::Filters::Before
- Defined in:
- 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.
166 167 168 169 170 |
# File 'lib/active_support/callbacks.rb', line 166 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.
171 172 173 |
# File 'lib/active_support/callbacks.rb', line 171 def filter @filter end |
#halted_lambda ⇒ Object (readonly)
Returns the value of attribute halted_lambda.
171 172 173 |
# File 'lib/active_support/callbacks.rb', line 171 def halted_lambda @halted_lambda end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
171 172 173 |
# File 'lib/active_support/callbacks.rb', line 171 def name @name end |
#user_callback ⇒ Object (readonly)
Returns the value of attribute user_callback.
171 172 173 |
# File 'lib/active_support/callbacks.rb', line 171 def user_callback @user_callback end |
#user_conditions ⇒ Object (readonly)
Returns the value of attribute user_conditions.
171 172 173 |
# File 'lib/active_support/callbacks.rb', line 171 def user_conditions @user_conditions end |
Instance Method Details
#apply(callback_sequence) ⇒ Object
189 190 191 |
# File 'lib/active_support/callbacks.rb', line 189 def apply(callback_sequence) callback_sequence.before(self) end |
#call(env) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/active_support/callbacks.rb', line 173 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 |