Class: Module

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

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


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 54

def dsl_accessor(*symbols)
  symbols.each { |sym|
    class_eval %{
      def #{sym}(*val)
        if val.empty?
          @#{sym}
        else
          @#{sym} = val.size == 1 ? val[0] : val
          # i am itching to deprecate next line XXX
          # @config["#{sym}"]=@#{sym} # commented out 2011-12-18 to simplify
          self # 2011-10-2 
        end
      end
    # can the next bypass validations
  attr_writer sym #2011-10-2 
    }
  }
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


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 75

def dsl_property(*symbols)
  symbols.each { |sym|
    class_eval %{
      def #{sym}(*val)
        if val.empty?
          @#{sym}
        else
          oldvalue = @#{sym}
          # @#{sym} = val.size == 1 ? val[0] : val
          tmp = val.size == 1 ? val[0] : val
          newvalue = tmp
          # i am itching to deprecate config setting
          if oldvalue.nil? || @_object_created.nil?
             @#{sym} = tmp
             # @config["#{sym}"]=@#{sym} # 2011-12-18 
          end
          return(self) if oldvalue.nil? || @_object_created.nil?

          if oldvalue != newvalue
            # trying to reduce calls to fire, when object is being created
             begin
               @property_changed = true
               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
         # TODO if Variable, take .value NEXT VERSION
         #{sym}(val)
      end
    }
  }
end