Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / module / attribute_accessors.rb
1 # Extends the module object with module and instance accessors for class attributes,
2 # just like the native attr* accessors for instance attributes.
3 #
4 # module AppConfiguration
5 # mattr_accessor :google_api_key
6 # self.google_api_key = "123456789"
7 #
8 # mattr_accessor :paypal_url
9 # self.paypal_url = "www.sandbox.paypal.com"
10 # end
11 #
12 # AppConfiguration.google_api_key = "overriding the api key!"
13 class Module
14 def mattr_reader(*syms)
15 syms.each do |sym|
16 next if sym.is_a?(Hash)
17 class_eval(<<-EOS, __FILE__, __LINE__)
18 unless defined? @@#{sym}
19 @@#{sym} = nil
20 end
21
22 def self.#{sym}
23 @@#{sym}
24 end
25
26 def #{sym}
27 @@#{sym}
28 end
29 EOS
30 end
31 end
32
33 def mattr_writer(*syms)
34 options = syms.extract_options!
35 syms.each do |sym|
36 class_eval(<<-EOS, __FILE__, __LINE__)
37 unless defined? @@#{sym}
38 @@#{sym} = nil
39 end
40
41 def self.#{sym}=(obj)
42 @@#{sym} = obj
43 end
44
45 #{"
46 def #{sym}=(obj)
47 @@#{sym} = obj
48 end
49 " unless options[:instance_writer] == false }
50 EOS
51 end
52 end
53
54 def mattr_accessor(*syms)
55 mattr_reader(*syms)
56 mattr_writer(*syms)
57 end
58 end