ruby on rails - Dynamically created method? _one_time_conditions_valid_718? -
I'm new to ROR and am jumping into a big ROR project. I used the railroad to make the diagram of all models and controllers. I have seen that as many controllers form start up in five ways
_one_time_conditions_valid_XXX? from XXX to 200 to 1116 However, these methods do not appear in the actual code. Are these methods generated automatically from some gem? I can not find any reference for it anywhere.
OK, you have these methods ActiveSupport :: callback :: callback A method is called in #_compile_per_key_options line 159 looks like this
Defining def in _compile_per_key_options key_options = _compile_options (@per_key) @ klass .class_eval & lt; & Lt; -RUBY_EVAL, __FILE__, __LINE__ + 1def_one_time_conditions_valid _ # {@ callback_id}? If true # {key_options} end of RUBY_EVAL end it is used first to supply data for , after Filters and #start via 2 different methods named code> and Check for methods such as #start and #end Code> Both> Code> #end
return if key & amp; Amp; ! Object.send ("_ one_time_conditions_valid _ # {@ callback_id}?") The complete purpose of these methods is to define a callback as the only way to determine it And then if there is compiling the appropriate hook then.
These hooks are clear about their names; first before the hook defined action and before the operation it takes the data to use, after < After the defined action / hook> the hook to run after the defined action and the action takes place, and the use of the data ASP hook is wrapped in a task and the event they trigger yield We do. You can also define your own like:
class records ActiveSupport :: Callback define_callbacks include: magic def magic run_callbacks: Magic puts "spells" end-end class magician & lt ; Record set_callback: Magic,: Before performing, performs the demonstration "Wizard will do a trick now" end set_callback: after magic, | Object Shows "Tada" and End
Wizard = Wizard New magician #Austruta: #Wizard: Now a trick # (before callback) #AbrcardaBra # (actual event) #Tada # (after callback) This means that your controllers have As many as "as many as five" are, the same as before_filter , after_filter , before_action , surrounding_app Filter volume (list available callback is too long)
Comments
Post a Comment