Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / class / delegating_attributes.rb
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 def self.#{name}?
23 !!#{name}
24 end
25 def #{name}?
26 !!#{name}
27 end
28 EOS
29 end
30 end
31
32 def superclass_delegating_writer(*names)
33 names.each do |name|
34 class_eval <<-EOS
35 def self.#{name}=(value)
36 @#{name} = value
37 end
38 EOS
39 end
40 end
41
42 def superclass_delegating_accessor(*names)
43 superclass_delegating_reader(*names)
44 superclass_delegating_writer(*names)
45 end
46 end