Skip to content

Instantly share code, notes, and snippets.

@csavage-mdsol
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csavage-mdsol/c82d91a16acdf9775d6f to your computer and use it in GitHub Desktop.
Save csavage-mdsol/c82d91a16acdf9775d6f to your computer and use it in GitHub Desktop.
farscape stuff

So for the active record-y interface, we're going to see naive method chains like this:

# transitions invocations
home.client_divisions.client_division(uuid).studies.create(params)
# Or trying to access an attribute
home.client_divisions.client_division(uuid).studies.study(uuid).name

Attributes should be terminal calls, and probably shouldn't exist outside of an if else or case statement, but if we have method missing return the representor self if it doesn't match a method, these chains will basically progress as far as they know how to. So if studies gets cool and is renamed studiez, the result of the above call would be the client division representor. Then we could write a meaningfull === for case statements, which would let code for dealing with this look like this:

case representor = home.client_divisions.client_division(uuid).studies.study(uuid)
when :study
  representor.name
when :studies
  # Do something smart
when :client_division
  # etc
when ...

This would also give us a clear place to do the semantic matching cleverness in the method missing block, allowing progression to the next call if its 'close enough'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment