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



108
109
110
# File 'lib/gather.rb', line 108

def own_properties
  @properties ||= UniqueArray.new
end

#propertiesObject

return properties for this class and ancestors



113
114
115
116
117
118
119
120
# File 'lib/gather.rb', line 113

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

#property(*symbols) ⇒ Object



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

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