Module: InheritableClassAttributes::ClassMethods
- Defined in:
- lib/inheritable_class_attributes.rb
Instance Method Summary collapse
- #cattr_inheritable_accessor(*symbols) ⇒ Object
- #cattr_inheritable_reader(*symbols) ⇒ Object
- #cattr_inheritable_writer(*symbols) ⇒ Object
- #inheritable_cattr_readers ⇒ Object
- #inheritable_cattr_writers ⇒ Object
- #inherited_with_inheritable_class_attributes(klass) ⇒ Object
Instance Method Details
#cattr_inheritable_accessor(*symbols) ⇒ Object
45 46 47 48 |
# File 'lib/inheritable_class_attributes.rb', line 45 def cattr_inheritable_accessor(*symbols) cattr_inheritable_writer(*symbols) cattr_inheritable_reader(*symbols) end |
#cattr_inheritable_reader(*symbols) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inheritable_class_attributes.rb', line 21 def cattr_inheritable_reader(*symbols) symbols.each do |symbol| self.inheritable_cattr_readers << symbol self.module_eval %{ def self.#{symbol} @#{symbol} end } end self.inheritable_cattr_readers.uniq! end |
#cattr_inheritable_writer(*symbols) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inheritable_class_attributes.rb', line 33 def cattr_inheritable_writer(*symbols) symbols.each do |symbol| self.inheritable_cattr_writers << symbol self.module_eval %{ def self.#{symbol}=(value) @#{symbol} = value end } end self.inheritable_cattr_writers.uniq! end |
#inheritable_cattr_readers ⇒ Object
13 14 15 |
# File 'lib/inheritable_class_attributes.rb', line 13 def inheritable_cattr_readers @inheritable_class_readers ||= [] end |
#inheritable_cattr_writers ⇒ Object
17 18 19 |
# File 'lib/inheritable_class_attributes.rb', line 17 def inheritable_cattr_writers @inheritable_class_writers ||= [] end |
#inherited_with_inheritable_class_attributes(klass) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/inheritable_class_attributes.rb', line 50 def inherited_with_inheritable_class_attributes(klass) inherited_without_inheritable_class_attributes(klass) if respond_to?(:inherited_without_inheritable_class_attributes) readers = inheritable_cattr_readers.dup writers = inheritable_cattr_writers.dup inheritables = [:inheritable_cattr_readers, :inheritable_cattr_writers] (readers + writers + inheritables).uniq.each do |attr| var = "@#{attr}" old_value = self.module_eval(var) new_value = (old_value.dup rescue old_value) klass.module_eval("#{var} = new_value") end end |