jnunemaker-httparty 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.7 2008-11-30
2
+ * 1 major enhancement
3
+ * fixed multiple class definitions overriding each others options
4
+
1
5
  == 0.1.6 2008-11-26
2
6
  * 1 major enhancement
3
7
  * now passing :query to set_form_data if post request to avoid content length errors
data/httparty.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{httparty}
5
- s.version = "0.1.6"
5
+ s.version = "0.1.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
9
- s.date = %q{2008-11-26}
9
+ s.date = %q{2008-11-30}
10
10
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
11
11
  s.email = ["nunemaker@gmail.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
@@ -2,7 +2,7 @@ module HTTParty
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/httparty.rb CHANGED
@@ -10,19 +10,48 @@ $:.unshift(directory) unless $:.include?(directory) || $:.include?(File.expand_p
10
10
 
11
11
  require 'httparty/request'
12
12
 
13
+ module ModuleLevelInheritableAttributes
14
+ def self.included(base)
15
+ base.extend(ClassMethods)
16
+ end
17
+
18
+ module ClassMethods
19
+ def mattr_inheritable(*args)
20
+ @mattr_inheritable_attrs ||= [:mattr_inheritable_attrs]
21
+ @mattr_inheritable_attrs += args
22
+ args.each do |arg|
23
+ module_eval %(
24
+ class << self; attr_accessor :#{arg} end
25
+ )
26
+ end
27
+ @mattr_inheritable_attrs
28
+ end
29
+
30
+ def inherited(subclass)
31
+ @mattr_inheritable_attrs.each do |inheritable_attribute|
32
+ instance_var = "@#{inheritable_attribute}"
33
+ subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
34
+ end
35
+ end
36
+ end
37
+ end
38
+
13
39
  module HTTParty
14
40
  class UnsupportedFormat < StandardError; end
15
41
  class RedirectionTooDeep < StandardError; end
16
-
42
+
17
43
  AllowedFormats = {:xml => 'text/xml', :json => 'application/json', :html => 'text/html'}
18
44
 
19
45
  def self.included(base)
20
46
  base.extend ClassMethods
47
+ base.send :include, ModuleLevelInheritableAttributes
48
+ base.send(:mattr_inheritable, :default_options)
49
+ base.instance_variable_set("@default_options", {})
21
50
  end
22
51
 
23
- module ClassMethods
52
+ module ClassMethods
24
53
  def default_options
25
- @@default_options ||= {}
54
+ @default_options
26
55
  end
27
56
 
28
57
  #
@@ -5,9 +5,16 @@ class Foo
5
5
  base_uri 'api.foo.com/v1'
6
6
  end
7
7
 
8
- class FooWithHttps
8
+ class GRest
9
9
  include HTTParty
10
- base_uri 'api.foo.com/v1:443'
10
+ base_uri "grest.com"
11
+ default_params :one => 'two'
12
+ end
13
+
14
+ class HRest
15
+ include HTTParty
16
+ base_uri "hrest.com"
17
+ default_params :two => 'three'
11
18
  end
12
19
 
13
20
  describe HTTParty do
@@ -117,4 +124,11 @@ describe HTTParty do
117
124
  end.should raise_error(HTTParty::RedirectionTooDeep)
118
125
  end
119
126
  end
127
+
128
+ describe "with multiple class definitions" do
129
+ it "should not run over each others options" do
130
+ HRest.default_options.should == {:base_uri => 'http://hrest.com', :default_params => {:two => 'three'}}
131
+ GRest.default_options.should == {:base_uri => 'http://grest.com', :default_params => {:one => 'two'}}
132
+ end
133
+ end
120
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnunemaker-httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-26 00:00:00 -08:00
12
+ date: 2008-11-30 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency