Sha256: e6264c586fda4e166d165c636fefdaa91d1d1883737b53e6472919b6de543cd4

Contents?: true

Size: 1 KB

Versions: 20

Compression:

Stored size: 1 KB

Contents

module HTTParty
  module ModuleInheritableAttributes #:nodoc:
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods #:nodoc:
      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

      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}
                #{ivar} = superclass.#{inheritable_attribute}.merge #{ivar}
              end
            EOM
            subclass.class_eval method
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
httparty-0.8.2 lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.6.alpha vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.5 vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.4 vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.3 vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.2 vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
nutshell-crm-0.0.1 vendor/bundle/gems/httparty-0.8.1/lib/httparty/module_inheritable_attributes.rb
httparty-0.8.1 lib/httparty/module_inheritable_attributes.rb
httparty-0.8.0 lib/httparty/module_inheritable_attributes.rb
httparty2-0.7.10 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.8 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.7 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.6 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.4 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.3 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.2 lib/httparty/module_inheritable_attributes.rb
httparty-0.7.0 lib/httparty/module_inheritable_attributes.rb
dnclabs-httparty-0.6.1.2010090201 lib/httparty/module_inheritable_attributes.rb
bartzon-httparty-0.6.1 lib/httparty/module_inheritable_attributes.rb
httparty-0.6.1 lib/httparty/module_inheritable_attributes.rb