1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Tucked module inheritable attributes in lib/httparty

This commit is contained in:
John Nunemaker 2009-01-31 00:53:26 -05:00
parent c5e229b696
commit ef61a4afd1
3 changed files with 28 additions and 28 deletions

View file

@ -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'

View file

@ -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

View file

@ -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