Home       Archives        About Me       Gallery       Contact       RSS
other places to go      thincSoft      revoluxions      my family blog

YAML SHMAML

Spent the day working with YAML and Ruby.  YAML is an object serialization strategy, and the integration with Ruby on Rails is really spectacular, it just kinda works. 

SOAP is to REST as
YAML is to XML

Below is my YAML file, isn't that purty?  Nice, readable, kind obvious what it does....

---
http_server:
port: 3000
server:
http://localhost/

live_feed:
path: /Xml/Feeds/
extension: .xml
toc: toc

I can read in the object

geoConfig = YAML::load(File.open("geoconfig.yaml"))

with and I can access the values with

http_server = @geoConfig['http_server']['server'].chomp('/')
#chomp off the trailing slash to normalize the name  

So, the above YAML file will get reinflated as:

{ 'http_server' => { 'port' => 3000, 'server' => 'http://localhost/' }, 'live_feed' => {'path'=>'/Xml/Feeds'},... }

 

The application we're working on interfaces with the backend datastore via REST.  As such we have dozens of URL endpoints scattered throughout the code.  We are developing the front end and the backend concurrently, so we stubbed out all the REST calls to query the local file system.  I needed a better configuration manager so they I could have scaffolding for my off-line Development, on-line development, and on-line production without having to add a switch statement to every class.

Enter YAML.  I set up a YAML configuration file for each development environment, and then put the url's in that file.

C# of course, has a similar concept, and is able to serialize objects to XML automatically also, but the code is a bit more verbose. 

GeoConfig myGeoConfig;
XmlSerializer mySerializer = new XmlSerializer(typeof(GeoConfig ));
FileStream myFS = new FileStream("geoconfig.xml", FileMode.Open);
myGeoConfig = (GeoConfig ) mySerializer.Deserialize(myFS);

Now, I need a C# YAML reader....





Posted on April 15, 2007 18:13

E-mail | Permalink | Comments (0) | Trackback

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

October 6. 2008 12:52








Categories

Blogroll






Copyright © 2005-2008 M. Andrew Eick.
Powered by BlogEngine.NET 1.3.0.0

Designed by Nukeation
Sign in