lib/rocx/elements/base_container.rb in rocx-0.5.6 vs lib/rocx/elements/base_container.rb in rocx-0.5.7
- old
+ new
@@ -7,11 +7,11 @@
def properties_tag(*args)
@properties_tag = args.first if args.any?
@properties_tag
end
- def property(name)
+ def value_property(name)
attr_reader name
define_method "#{name}=" do |value|
class_name = name.to_s.split("_").map(&:capitalize).join
prop_class = Rocx::Properties.const_get class_name
@@ -19,10 +19,25 @@
end
properties << name
end
+ def property(name)
+ define_method "#{name}" do
+ class_name = name.to_s.split("_").map(&:capitalize).join
+ prop_class = Rocx::Properties.const_get class_name
+
+ if instance_variable_get("@#{name}").nil?
+ instance_variable_set "@#{name}", prop_class.new
+ end
+
+ instance_variable_get "@#{name}"
+ end
+
+ properties << name
+ end
+
def properties
@properties ||= []
end
end
@@ -44,10 +59,10 @@
protected
def property_xml(xml)
props = properties.map(&method(:send)).compact
- return if props.empty?
+ return if props.none?(&:render?)
xml[namespace].public_send(properties_tag) {
props.each { |prop| prop.to_xml(xml) }
}
end