storage_room 0.3.10 → 0.3.11

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/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == Version 0.3.11
2
+ * Fixed another cyclic dependency bug
3
+
1
4
  == Version 0.3.10
2
5
  * Fixed cyclic dependency when preloading associated Collections
3
6
  * Added create, update, save and destroy callbacks to Models
data/README.rdoc CHANGED
@@ -37,6 +37,12 @@ This is a walkthrough with all steps you need to setup a devise entry, including
37
37
 
38
38
  You can find the documentation at http://rdoc.info/github/thriventures/storage_room_gem.
39
39
 
40
+ == Long Running Processes
41
+
42
+ The gem caches responses from the API. If you have a long-running process such as a server or worker you probably want fresh data and you should clear the cache before each request:
43
+
44
+ StorageRoom::IdentityMap.clear
45
+
40
46
  == More Examples
41
47
 
42
48
  See the examples folder.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.10
1
+ 0.3.11
@@ -146,6 +146,11 @@ module StorageRoom
146
146
  end
147
147
 
148
148
  module ClassMethods
149
+ # Is the passed hash of response data a real object or only an association with a URL but no actual data
150
+ def response_data_is_association?(hash)
151
+ hash.size == 2 && hash.include?('@type') && hash.include?('url')
152
+ end
153
+
149
154
  # Load an object with the specified URL from the API
150
155
  def load(url, parameters = {})
151
156
  return nil if url.blank?
@@ -37,10 +37,14 @@ module StorageRoom
37
37
  def new_from_response_data(response_data)
38
38
  url = response_data['@url'] || response_data['url']
39
39
  object = url ? identity_map[url] : nil
40
-
40
+
41
41
  if object.present? && identity_map_on?
42
- StorageRoom.log("Loaded #{object} (#{url}) from identity map (new_from_response_data)")
43
- object.set_from_response_data(response_data)
42
+ if object.loaded? && response_data_is_association?(response_data)
43
+ StorageRoom.log("Loaded #{object} (#{url}) from identity map (new_from_response_data)")
44
+ else
45
+ StorageRoom.log("Loaded #{object} (#{url}) from identity map and updated attributes (new_from_response_data)")
46
+ object.set_from_response_data(response_data)
47
+ end
44
48
  else
45
49
  object = super
46
50
  if identity_map_on? && url.present? && object.is_a?(Model)
@@ -4,8 +4,6 @@ module StorageRoom
4
4
  include HTTParty
5
5
  extend Plugins
6
6
 
7
-
8
-
9
7
  include Accessors
10
8
 
11
9
  plugin IdentityMap
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  describe StorageRoom::TestAccessors do
13
13
  context "Class" do
14
- describe "new_from_json_file" do
14
+ describe "#new_from_json_file" do
15
15
  it "should open file" do
16
16
  path = fixture_path('export_collection.json')
17
17
  object = StorageRoom::Resource.new_from_json_file(path)
@@ -19,6 +19,22 @@ describe StorageRoom::TestAccessors do
19
19
  end
20
20
  end
21
21
 
22
+ describe "#response_data_is_association?" do
23
+ it "should return true" do
24
+ hash = {'@type' => 'Tour', 'url' => 'URL'}
25
+ StorageRoom::Resource.response_data_is_association?(hash).should be_true
26
+ end
27
+
28
+ it "should return false for too many keys" do
29
+ hash = {'@type' => 'Tour', 'url' => 'URL', 'more' => 3}
30
+ StorageRoom::Resource.response_data_is_association?(hash).should be_false
31
+ end
32
+
33
+ it "should return false for wrong keys" do
34
+ hash = {'@type' => 'Tour', 'more' => 3}
35
+ StorageRoom::Resource.response_data_is_association?(hash).should be_false
36
+ end
37
+ end
22
38
  end
23
39
 
24
40
 
data/storage_room.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{storage_room}
8
- s.version = "0.3.10"
8
+ s.version = "0.3.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sascha Konietzke"]
12
- s.date = %q{2011-08-03}
12
+ s.date = %q{2011-08-04}
13
13
  s.description = %q{StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.}
14
14
  s.email = %q{sascha@thriventures.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 10
9
- version: 0.3.10
8
+ - 11
9
+ version: 0.3.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sascha Konietzke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-03 00:00:00 +02:00
17
+ date: 2011-08-04 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency