Creating Objects From an XML Based Registry Using the Xmlregistry_objects Gem

require 'xmlregistry_objects'


s =<<REG
app/app1
admin: jrobertson
pin_no: 1234

app/app2
admin: dsmith
pin_no: 4321

hkey_network/thinclient
active: false
name: niko2

hkey_apps/email
new: true
last_received: #20-Aug-2014 @ 09:10#

hkey_apps/suntimes
sunrise: #05:45#
sunset: #08:43#
REG

reg = DWSRegistry.new 
reg.import s

# the following nested list maps the registry key with 
#                                        associated object and attributes
list = <<EOF
thinclient = [hkey_network/thinclient]
  active? = active
  name = name
email = [hkey_apps/email]
  new? = new
  latest = last_received
sun = [hkey_apps/suntimes]
EOF
 

xro = XMLRegistryObjects.new(reg,list)
h = xro.to_h

eval xro.define_methods

email.new? #=> true 
email.latest #=> 2014-08-20 09:10:00 +0100 

sun.sunset #=> 2015-03-04 08:43:00 +0000 


The above example demonstrates how objects can be created from the XML registry. The intention is to make it as readable as possible to write rules to determine if an event should execute or not.

Resources