method
write_generation
v2.1.0 -
Show latest stable
- Class:
ActionController::Routing::Route
write_generation()public
Write and compile a generate method for this Route.
# File actionpack/lib/action_controller/routing/route.rb, line 26
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.)
method_decl = "def generate(#{args})\npath, hash = generate_raw(options, hash, expire_on)\nappend_query_string(path, hash, extra_keys(options))\nend"
instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
method_decl = "def generate_extras(#{args})\npath, hash = generate_raw(options, hash, expire_on)\n[path, extra_keys(options)]\nend"
instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
raw_method
end Related methods
- Instance methods
- append_query_string
- build_query_string
- defaults
- extra_keys
- generate
- generate_extras
- generation_extraction
- generation_requirements
- generation_structure
- matches_controller_and_action?
- optimise?
- parameter_shell
- recognition_conditions
- recognition_extraction
- recognition_pattern
- recognize
- segment_keys
- significant_keys
- to_s
- write_generation
- write_recognition
- Class methods
- new
- Protected methods
-
requirement_for