method
write_generation!
v2.3.8 -
Show latest stable
- Class:
ActionController::Routing::Route
write_generation!()private
Write and compile a generate method for this Route.
# File actionpack/lib/action_controller/routing/route.rb, line 150
def write_generation!
# Build the main body of the generation
body = "expired = false\n#{generation_extraction}\n#{generation_structure}"
# If we have conditions that must be tested first, nest the body inside an if
body = "if #{generation_requirements}\n#{body}\nend" if generation_requirements
args = "options, hash, expire_on = {}"
# Nest the body inside of a def block, and then compile it.
raw_method = method_decl = "def generate_raw(#{args})\npath = begin\n#{body}\nend\n[path, hash]\nend"
instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
# expire_on.keys == recall.keys; in other words, the keys in the expire_on hash
# are the same as the keys that were recalled from the previous request. Thus,
# we can use the expire_on.keys to determine which keys ought to be used to build
# the query string. (Never use keys from the recalled request when building the
# query string.)
raw_method
end Related methods
- Instance methods
- build_query_string
- defaults
- freeze
- generate
- generate_extras
- matches_controller_and_action?
- optimise?
- parameter_shell
- required_segment_keys
- segment_keys
- significant_keys
- to_s
- Class methods
- new
- Private methods
-
append_query_string -
extra_keys -
generation_extraction -
generation_requirements -
generation_structure -
prepare_matching! -
recognition_conditions -
recognition_extraction -
recognition_pattern -
requirement_for -
write_generation! -
write_recognition!