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.3
1
+ 0.0.4
@@ -3,8 +3,7 @@ require 'hashie'
3
3
  class Resterl::BaseObject #< Hashie::Mash
4
4
 
5
5
  include ClassLevelInheritableAttributes
6
- inheritable_attributes :resterl_client, :parser, :complete_mime_type,
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, :read, :delete
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 inheritable_attributes(*args)
10
- @resterl_inheritable_attributes ||= [:inheritable_attributes]
11
- @resterl_inheritable_attributes += args
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
- @resterl_inheritable_attributes
18
+ @cattr_inheritable_attrs
18
19
  end
19
20
 
20
21
  def inherited(subclass)
21
- @resterl_inheritable_attributes.each do |inheritable_attribute|
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resterl}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Florian Dütsch"]
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
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Florian D\xC3\xBCtsch"