public Method

Route.write_generation

Write and compile a generate method for this Route.

Source Code

# File 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
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.