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:
parent
c5e229b696
commit
ef61a4afd1
3 changed files with 28 additions and 28 deletions
|
@ -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'
|
||||
|
|
25
lib/httparty/module_inheritable_attributes.rb
Normal file
25
lib/httparty/module_inheritable_attributes.rb
Normal 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
|
|
@ -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
|
Loading…
Reference in a new issue