Skip to content
kristianmandrup edited this page Sep 14, 2010 · 9 revisions

The Ruby code Query and Manipulation Language (Ruby QML) is a DSL for querying, traversing and manipulating Ruby code.
Ruby QML is a language for accessing and manipulating Ruby code, much like SQL is a language for accessing and manipulating tables in a database.

APIs

Ruby QML consists of two distinct APIs

  • Ruby code Query Language (Ruby QL)
  • Ruby code Manipulating Language (Ruby ML)

Ruby code Query Language

See Query API for more details.

  • find(type, …)
  • inside(type, …) do |node|

The method inside is merely an alias for find which requires a block argument.
Note a block argument can also be given for find.
The argument type is a symbol indicating the Node type to find.
There is currently support for finding the following Node types:

  • :module
  • :class
  • :variable
  • :assignment
  • :call
  • :block
  • :def (or :method)

Ruby Nodes that you find using the Ruby QL can be manipulated using the Ruby ML.

Ruby code Manipulation Language

See Manipulation API for more details.

Manipulation commands supported on Ruby nodes:

  • insert
  • update
  • delete

Insert

  • insert(:before, code)
  • insert (:after, code)

Update

  • update(:select => {…}, :with => {..}, &block)
  • update(:select => {…}, :with_code => ‘…’, &block)

For assignment nodes (fx b = 7)

  • update(:value, &block)

Delete

  • delete

See test directory for more detailed examples of use.