resterl 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/resterl/base_object.rb
CHANGED
@@ -3,8 +3,7 @@ require 'hashie'
|
|
3
3
|
class Resterl::BaseObject #< Hashie::Mash
|
4
4
|
|
5
5
|
include ClassLevelInheritableAttributes
|
6
|
-
|
7
|
-
:mapper
|
6
|
+
cattr_inheritable :resterl_client, :parser, :complete_mime_type, :mapper
|
8
7
|
|
9
8
|
#self.resterl_client = nil
|
10
9
|
#self.complete_mime_type = 'text/plain'
|
@@ -34,6 +33,7 @@ class Resterl::BaseObject #< Hashie::Mash
|
|
34
33
|
when :json
|
35
34
|
[proc {|str| JSON.parse(str)}, 'application/json']
|
36
35
|
when :xml
|
36
|
+
# TODO: Only works when Rails is loaded?
|
37
37
|
[proc {|str| Hash.from_xml(str)}, 'application/xml']
|
38
38
|
end
|
39
39
|
end
|
@@ -6,8 +6,14 @@ class Resterl::Caches::RailsMemcachedCache < Resterl::Caches::CacheInterface
|
|
6
6
|
@client = client
|
7
7
|
end
|
8
8
|
|
9
|
-
def_delegators :@client, :
|
9
|
+
def_delegators :@client, :delete
|
10
10
|
|
11
|
+
def read key
|
12
|
+
obj = @client.read key
|
13
|
+
# Rails freezes the object when putting it put the cache.
|
14
|
+
# So unfreeze it:
|
15
|
+
obj ? obj.dup : obj
|
16
|
+
end
|
11
17
|
def write key, value, expires_in
|
12
18
|
@client.write key, value, :expires_in => expires_in
|
13
19
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
# From:
|
2
2
|
# http://railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/
|
3
|
+
# http://railstips.org/blog/archives/2008/06/12/a-class-instance-variable-update/
|
3
4
|
module ClassLevelInheritableAttributes
|
4
5
|
def self.included(base)
|
5
6
|
base.extend(ClassMethods)
|
6
7
|
end
|
7
8
|
|
8
9
|
module ClassMethods
|
9
|
-
def
|
10
|
-
@
|
11
|
-
@
|
10
|
+
def cattr_inheritable(*args)
|
11
|
+
@cattr_inheritable_attrs ||= [:cattr_inheritable_attrs]
|
12
|
+
@cattr_inheritable_attrs += args
|
12
13
|
args.each do |arg|
|
13
14
|
class_eval %(
|
14
15
|
class << self; attr_accessor :#{arg} end
|
15
16
|
)
|
16
17
|
end
|
17
|
-
@
|
18
|
+
@cattr_inheritable_attrs
|
18
19
|
end
|
19
20
|
|
20
21
|
def inherited(subclass)
|
21
|
-
@
|
22
|
+
@cattr_inheritable_attrs.each do |inheritable_attribute|
|
22
23
|
instance_var = "@#{inheritable_attribute}"
|
23
24
|
subclass.instance_variable_set(instance_var,
|
24
25
|
instance_variable_get(instance_var))
|
data/resterl.gemspec
CHANGED
data/test/test_resterl.rb
CHANGED
@@ -30,6 +30,27 @@ class TestResterl < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
|
+
|
34
|
+
should 'work with deeper nestings (cattr_inheritable)' do
|
35
|
+
|
36
|
+
assert_nothing_raised do
|
37
|
+
|
38
|
+
class Test::BaseObject < Resterl::BaseObject
|
39
|
+
self.mime_type = :json
|
40
|
+
self.resterl_client = 1
|
41
|
+
end
|
42
|
+
|
43
|
+
class Test::T1 < Test::BaseObject
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
Test::T1.complete_mime_type
|
49
|
+
Test::T1.resterl_client
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
33
54
|
|
34
55
|
end
|
35
56
|
|