Module: Gather::ClassMethods

Included in:
Changes::ClassMethods
Defined in:
lib/gather.rb

Instance Method Summary collapse

Instance Method Details

#own_propertiesObject

return properties for only this class



105
106
107
# File 'lib/gather.rb', line 105

def own_properties
  @properties ||= UniqueArray.new
end

#propertiesObject

return properties for this class and ancestors



110
111
112
113
114
115
116
117
# File 'lib/gather.rb', line 110

def properties
  own_properties +
  if superclass.respond_to? :properties
    superclass.properties
  else
    []
  end
end

#property(*symbols) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/gather.rb', line 119

def property( *symbols )
  @stripper_re ||= /^([^\= ]+)\s*\=?\s*$/
  symbols.each do |sym|
    stripped = @stripper_re.match( sym.to_s )[1]
    own_properties << stripped.to_sym
    line, st = __LINE__, <<-EOF
      def #{stripped}(*val, &block)
        if block.nil?
          if val.empty?
            @#{stripped}
          else
            # use the assignment, so only it has to be overloaded
            self.#{stripped} = val.size == 1 ? val[0] : val
          end
        else
          @#{stripped} = block
        end
      end
      
      def #{stripped}=( value )
        @#{stripped} = value
      end
    EOF
    class_eval st, __FILE__, line + 1
  end
end