Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_extensions_plugins / plugins / scenarios / lib / scenarios / extensions / .svn / text-base / delegating_attributes.rb.svn-base
blobf5f0ef87792f041a417c336c820dff66e5e4bdb7
1 # These class attributes behave something like the class
2 # inheritable accessors.  But instead of copying the hash over at
3 # the time the subclass is first defined,  the accessors simply
4 # delegate to their superclass unless they have been given a 
5 # specific value.  This stops the strange situation where values 
6 # set after class definition don't get applied to subclasses.
7 class Class
8   def superclass_delegating_reader(*names)
9     class_name_to_stop_searching_on = self.superclass.name.blank? ? "Object" : self.superclass.name
10     names.each do |name|
11       class_eval <<-EOS
12       def self.#{name}
13         if defined?(@#{name})
14           @#{name}
15         elsif superclass < #{class_name_to_stop_searching_on} && superclass.respond_to?(:#{name})
16           superclass.#{name}
17         end
18       end
19       def #{name}
20         self.class.#{name}
21       end
22       EOS
23     end
24   end
26   def superclass_delegating_writer(*names)
27     names.each do |name|
28       class_eval <<-EOS
29         def self.#{name}=(value)
30           @#{name} = value
31         end
32       EOS
33     end
34   end
36   def superclass_delegating_accessor(*names)
37     superclass_delegating_reader(*names)
38     superclass_delegating_writer(*names)
39   end
40 end