Module: ActiveResourceThrottle::ClassInheritableAttributes

Included in:
ClassMethods
Defined in:
lib/active_resource_throttle.rb

Overview

Add class inheritable attributes. See John Nunemaker’s article at railstips.org/2008/6/13/a-class-instance-variable-update

Instance Method Summary collapse

Instance Method Details

#cattr_inheritable(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/active_resource_throttle.rb', line 10

def cattr_inheritable(*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



21
22
23
24
25
26
# File 'lib/active_resource_throttle.rb', line 21

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))
  end
end