class Module
Public Instance Methods
dsl_accessor(*symbols)
click to toggle source
others may not want this, sets config, so there's a duplicate hash
also creates a attr_writer so you can use =.
2011-10-2 V1.3.1 Now returning self, so i can chain calls
# File lib/canis/core/widgets/rwidget.rb, line 71 def dsl_accessor(*symbols) symbols.each { |sym| class_eval %{ def #{sym}(*val) if val.empty? @#{sym} else @#{sym} = val.size == 1 ? val[0] : val self # 2011-10-2 end end # can the next bypass validations attr_writer sym } } end
dsl_property(*symbols)
click to toggle source
Besides creating getters and setters, this also fires property change handler if the value changes, and after the object has been painted once.
2011-10-2 V1.3.1 Now returning self, so i can chain calls
# File lib/canis/core/widgets/rwidget.rb, line 90 def dsl_property(*symbols) symbols.each { |sym| class_eval %{ def #{sym}(*val) if val.empty? @#{sym} else oldvalue = @#{sym} tmp = val.size == 1 ? val[0] : val newvalue = tmp if @_object_created.nil? @#{sym} = tmp end return(self) if @_object_created.nil? if oldvalue != newvalue # trying to reduce calls to fire, when object is being created begin fire_property_change("#{sym}", oldvalue, newvalue) if !oldvalue.nil? @#{sym} = tmp @config["#{sym}"]=@#{sym} rescue PropertyVetoException $log.warn "PropertyVetoException for #{sym}:" + oldvalue.to_s + "-> "+ newvalue.to_s end end # if old self end # if val end # def #attr_writer sym def #{sym}=val #{sym}(val) end } } end
dsl_writer(*symbols)
click to toggle source
divert an = call to the dsl_property
or accessor call.
This is required if I am bypassing dsl_property for some extra processing as in color and bgcolor but need the rest of it.
# File lib/canis/core/widgets/rwidget.rb, line 128 def dsl_writer(*symbols) symbols.each { |sym| class_eval %{ def #{sym}=(val) #{sym}(val) end } } end