Module: HTTParty::ModuleInheritableAttributes::ClassMethods

Defined in:
lib/httparty/module_inheritable_attributes.rb

Overview

:nodoc:

Instance Method Summary (collapse)

Instance Method Details

- (Object) inherited(subclass)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/httparty/module_inheritable_attributes.rb', line 36

def inherited(subclass)
  super
  @mattr_inheritable_attrs.each do |inheritable_attribute|
    ivar = "@#{inheritable_attribute}"
    subclass.instance_variable_set(ivar, instance_variable_get(ivar).clone)

    if instance_variable_get(ivar).respond_to?(:merge)
      method = <<-EOM
        def self.#{inheritable_attribute}
          duplicate = ModuleInheritableAttributes.hash_deep_dup(#{ivar})
          #{ivar} = superclass.#{inheritable_attribute}.merge(duplicate)
        end
      EOM

      subclass.class_eval method
    end
  end
end

- (Object) mattr_inheritable(*args)



25
26
27
28
29
30
31
32
33
34
# File 'lib/httparty/module_inheritable_attributes.rb', line 25

def mattr_inheritable(*args)
  @mattr_inheritable_attrs ||= [:mattr_inheritable_attrs]
  @mattr_inheritable_attrs += args

  args.each do |arg|
    module_eval %(class << self; attr_accessor :#{arg} end)
  end

  @mattr_inheritable_attrs
end