Learning Ruby – for buildr

I decided to learn ruby for using buildr as my build system for the diploma thesis. So, I looked for a book your guide to learn it. And I found an excellent and funny one which represents the syntax, semantic and much more of ruby.

It can be downloaded here: http://www.scribd.com/doc/8545174/Whys-Poignant-Guide-to-Ruby

I now summarize the key features of ruby to be able to read and understand ruby as fast as possible:

  • name or name_asd or name1_a_1 is variable
  • Name is a constant (as its The Empire State Building)
  • $varname is a global variable (everybody behaves the same way if you give him a $)
  • @varname is an instance variable  (speak: attribute)
  • @@varname is a class variable (speak: attribute for all)
  • :name is a symbol
  • { print “test” } is a block as it is do print “test” end
  • { |x,y| x + y } where x,y is a block argument representing input parameters of the block
  • (1..5) or (‘a’ .. ‘z’) are ranges, like an accordeon (a third dot includes the last element, too)
  • [1, 2, 3] is an array
  • {‘xml’ => ‘eXtensible Markup Language’, ‘sql’ => ‘Structured Query Language’} is a dictionary
  • /regex/ contains a regular expression
  • nil represents emptyness
  • << is the concatenation operator, which is a method
  • puts print something on console
  • gets reads from user input
  • def is used to define methods
  • case is used with when to switch over the characteristics of a variable
  • initialize is the default constructor
  • < means inheritance or extends from the java perspektive
  • class classname creates a class and has to be ended using the keyword end
  • wrap code together using modules
  • attr_accessor :picks, :purchased is a shortcut for creating getter and setter for the variables picks and purchased
    attr_reader :picks, :purchased is used for creating only getters

I thinks, this should now suffice to work with buildr. I will update this while I dig through buildr to automate my transformation process.

Automating EMF Tasks – Codegeneration

In order to execute the task of code generation of an EMF model, an ant task is quite handy to do this. Here is an example for this:

<exec executable="${eclipse.exe}">
	<arg value="-noSplash" />
	<arg value="-data ${workspace_location}" />
	<arg value="-model" />
	<arg value="-edit" />
	<arg value="-editor" />
	<arg value="-tests" />
	<arg value="-application" />
	<arg value="org.eclipse.emf.codegen.ecore.Generator" />
	<arg value="${genmodel}" />

You can omit parameters like -edit if you do not need these parts.

Currently, I try to find an automation of the following tasks:

  • Clean the code generation (this can also be done using a simple delete command on the filesystem)
  • Create a genmodel from an ecore model
  • Reload a genmodel by an ecore model
  • Start an eclipse instance with the created plugins in its runtime