From: Jatinder Singh Date: 2006-06-15T02:26:49+09:00 Subject: Using YAML as a data DSL ------=_Part_130901_23172506.1150306005501 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I have an RoR application which has various GUI screens for taking input from users for creating some entities in my application. What ever information is given by the user I am putting in to a datastructure in ruby(I have created a set of classes in ruby for that purpose), To give you an example say there is a Music store and there are various records of various artists available. we can have following classes for storing the information entered by user for records and artists, class Record @name #array for storing objects of artist class @artists end class Artist @name @phone end Note: ofcourse we can use a db here and update the info entered by user directly in the database, but may be I am giving a wrong example here, actually the above information about entities is entered by user only once. Now I want to give the end user, a way to circumvent GUI and directly write in to a file the information about the entities in a format specified by me(thats what a DSL is all about). Following is what I intend to have with respect to DSL 1. This DSL would be more of a data DSL then a business DSL which is meant for defining business rules. 2. It should be user friendly(who doesn't want a DSL to be user friendly) with these goals in mind I wrote an internal DSL(having ruby method calls) and wrote some code which populates above mentioned classes(Record and Artist). I worked in other direction of using YAML as DSL; for that I created a YAML compliant file with following contents, ########################### --- !ruby/object:Video artist: Jatinder name: SampleVideo type: Pop ########################### YAML provides a way to persist objects in text format which is I believe very user friendly, so what I thought is that a user can create a file with above contents and then use YAML::load method to load above file's content in to ruby object. Well in this case I really dont have to do much, as in I dont have to write a parser. There might be several deficiencies/probelms in the 2nd approach, few of them I think are, 1. YAML has a strict format, even if a ":" goes here and there then the whole file goes for a toss. 2. In the above file, I would definately not like to have "!ruby/object"..can I override that somehow?(ofcourse I can have a layer between YAML and file, which modifies the file to change the file structure/contents to make it YAML compliant). 3. is YAML stable enough? I read about syck..it seems to solve the problem of solving perf issues. Any thought's on above appraoch? Regards, Jatinder ------=_Part_130901_23172506.1150306005501--