Module: Chingu::Helpers::ClassInheritableAccessor::ClassMethods

Defined in:
lib/chingu/helpers/class_inheritable_accessor.rb

Instance Method Summary collapse

Instance Method Details

#class_inheritable_accessor(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/chingu/helpers/class_inheritable_accessor.rb', line 13

def class_inheritable_accessor(*args)
  @cattr_inheritable_attrs ||= [:cattr_inheritable_attrs]
  @cattr_inheritable_attrs += args
  args.each do |arg|
  class_eval %(
    class << self; attr_accessor :#{arg} end
  )
  end
  @cattr_inheritable_attrs
end

#inherited(subclass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chingu/helpers/class_inheritable_accessor.rb', line 24

def inherited(subclass)
  @cattr_inheritable_attrs.each do |inheritable_attribute|
    instance_var = "@#{inheritable_attribute}" 
    subclass.instance_variable_set(instance_var, instance_variable_get(instance_var).dup)
					
    #if instance_var =~ /trait_options/
    #	puts "#{self.to_s} -> #{subclass.to_s}: #{instance_var}"	# DEBUG
    #	puts instance_variable_get(instance_var)
    #	puts "------"
    #end
  end
  super
end