Class: Module

Inherits:
Object show all
Defined in:
lib/canis/core/widgets/rwidget.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#dsl_accessor(*symbols) ⇒ Object

also creates a attr_writer so you can use =.

2011-10-2 V1.3.1 Now returning self, so i can chain calls


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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) ⇒ Object

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


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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) ⇒ Object

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.


128
129
130
131
132
133
134
135
136
# 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