Class: XMLRegistryObjects
- Inherits:
-
Object
- Object
- XMLRegistryObjects
- Defined in:
- lib/xmlregistry_objects.rb
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Instance Method Summary collapse
- #define_methods ⇒ Object
-
#initialize(reg, obj) ⇒ XMLRegistryObjects
constructor
A new instance of XMLRegistryObjects.
Constructor Details
#initialize(reg, obj) ⇒ XMLRegistryObjects
Returns a new instance of XMLRegistryObjects.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/xmlregistry_objects.rb', line 14 def initialize(reg, obj) polyrexdoc = if obj.is_a? Polyrex then obj elsif obj.is_a? String then buffer, type = RXFHelper.read obj if type == :url then Polyrex.new buffer else Polyrex.new.import "<?polyrex schema='entries/object[name, regkey]/"\ "methodx[name,subkeyname]' delimiter=' = '?>\n" + obj end end @to_h = polyrexdoc.records.inject({}) do |rtn, row| name, path = row.name, row.regkey[1..-2] class_name = name.capitalize klass = Object.const_set(class_name,Class.new) s = " def initialize(reg) @reg = reg end def last_modified() lm = @reg.get_key('#{path}').attributes[:last_modified] Time.parse(lm) if lm end " s = if row.records.any? then row.records.inject(s) do |r, attr| attr_name, subkey = attr.name, attr.subkeyname key = path + '/' + subkey r << make_def(key, attr_name) r << make_setdef(key, attr_name[/\w+/]) end else a = reg.xpath("#{path}/*") a.inject(s) do |r, x| methods_name = subkey = x.name type = x.attributes[:class] key = path + '/' + subkey r << make_setdef(key, method_name=subkey) method_name += '?' if type and type.first == 'boolean' r << make_def(key, method_name) end end klass.class_eval s rtn.merge name.to_sym => klass.new(reg) end end |
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
12 13 14 |
# File 'lib/xmlregistry_objects.rb', line 12 def to_h @to_h end |
Instance Method Details
#define_methods ⇒ Object
85 86 87 |
# File 'lib/xmlregistry_objects.rb', line 85 def define_methods() @to_h.each.map {|k,v| "define_method :#{k.to_s}, ->{h[:#{k}]}"}.join("\n") end |