From ef61a4afd113247be08643ee003462fec6d85be1 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Sat, 31 Jan 2009 00:53:26 -0500 Subject: [PATCH] Tucked module inheritable attributes in lib/httparty --- lib/httparty.rb | 6 ++--- lib/httparty/module_inheritable_attributes.rb | 25 +++++++++++++++++++ lib/module_level_inheritable_attributes.rb | 25 ------------------- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 lib/httparty/module_inheritable_attributes.rb delete mode 100644 lib/module_level_inheritable_attributes.rb diff --git a/lib/httparty.rb b/lib/httparty.rb index f269be9..67cb9f9 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -2,8 +2,8 @@ $:.unshift(File.dirname(__FILE__)) require 'net/http' require 'net/https' -require 'module_level_inheritable_attributes' require 'core_extensions' +require 'httparty/module_inheritable_attributes' module HTTParty @@ -19,7 +19,7 @@ module HTTParty def self.included(base) base.extend ClassMethods - base.send :include, ModuleLevelInheritableAttributes + base.send :include, HTTParty::ModuleInheritableAttributes base.send(:mattr_inheritable, :default_options) base.instance_variable_set("@default_options", {}) end @@ -129,9 +129,9 @@ module HTTParty end end +require 'httparty/cookie_hash' require 'httparty/exceptions' require 'httparty/request' require 'httparty/response' require 'httparty/json' require 'httparty/xml' -require 'httparty/cookie_hash' diff --git a/lib/httparty/module_inheritable_attributes.rb b/lib/httparty/module_inheritable_attributes.rb new file mode 100644 index 0000000..0afe608 --- /dev/null +++ b/lib/httparty/module_inheritable_attributes.rb @@ -0,0 +1,25 @@ +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) + @mattr_inheritable_attrs.each do |inheritable_attribute| + instance_var = "@#{inheritable_attribute}" + subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) + end + end + end + end +end \ No newline at end of file diff --git a/lib/module_level_inheritable_attributes.rb b/lib/module_level_inheritable_attributes.rb deleted file mode 100644 index fbad5c4..0000000 --- a/lib/module_level_inheritable_attributes.rb +++ /dev/null @@ -1,25 +0,0 @@ -module ModuleLevelInheritableAttributes #: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) - @mattr_inheritable_attrs.each do |inheritable_attribute| - instance_var = "@#{inheritable_attribute}" - subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) - end - end - end -end