vidibus-resource 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class Api::ResourcesController < ApiController
5
5
  # Creates resource consumer on provider.
6
6
  def create
7
7
  @instance.add_resource_consumer(params["service"])
8
- render :json => {:resource => @instance.resourceable_hash}
8
+ render :json => {:resource => @instance.fixed_resourceable_hash}
9
9
  end
10
10
 
11
11
  # Updates resource on consumer.
@@ -22,8 +22,8 @@ module Vidibus::Resource
22
22
  # Registers this consumer with provider.
23
23
  def add_resource_consumer
24
24
  response = resource_provider.post("/api/resources/#{self.class.to_s.tableize}/#{uuid}")
25
- resource = response["resource"]
26
- self.resource_attributes = resource
25
+ data = response["resource"]
26
+ self.resource_attributes = fix_resource_attributes(data)
27
27
  set_resource_attributes(true)
28
28
  true # ensure true!
29
29
  end
@@ -37,6 +37,7 @@ module Vidibus::Resource
37
37
  # Updates resource attributes.
38
38
  # TODO: Update only data that has been changed.
39
39
  def update_resource_attributes(data)
40
+ data = fix_resource_attributes(data)
40
41
  update_attributes(:resource_attributes => data)
41
42
  end
42
43
 
@@ -89,6 +90,16 @@ module Vidibus::Resource
89
90
  end
90
91
  end
91
92
 
93
+ # Fix empty arrays
94
+ def fix_resource_attributes(data)
95
+ for key, value in data
96
+ if value === [EMPTY_ARRAY_IDENTIFIER]
97
+ data[key] = []
98
+ end
99
+ end
100
+ data
101
+ end
102
+
92
103
  module ClassMethods
93
104
 
94
105
  # Sets up resource provider service type and realm.
@@ -39,6 +39,16 @@ module Vidibus::Resource
39
39
  attributes
40
40
  end
41
41
 
42
+ # Fix empty arrays
43
+ def fixed_resourceable_hash
44
+ for key, value in resourceable_hash
45
+ if value === []
46
+ resourceable_hash[key] = [EMPTY_ARRAY_IDENTIFIER]
47
+ end
48
+ end
49
+ resourceable_hash
50
+ end
51
+
42
52
  protected
43
53
 
44
54
  # Update resource consumers if significant changes were made.
@@ -48,7 +58,7 @@ module Vidibus::Resource
48
58
  return unless resource_consumers and resource_consumers.any?
49
59
  return unless changes.except("resource_consumers", "updated_at").any?
50
60
 
51
- hash = resourceable_hash
61
+ hash = fixed_resourceable_hash
52
62
  hash_checksum = Digest::MD5.hexdigest(hash.to_s)
53
63
  unless hash_checksum == resourceable_hash_checksum
54
64
  self.resourceable_hash_checksum = hash_checksum
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Resource
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,2 +1,8 @@
1
+ module Vidibus
2
+ module Resource
3
+ EMPTY_ARRAY_IDENTIFIER = "__r::array__"
4
+ end
5
+ end
6
+
1
7
  require "resource/provider/mongoid"
2
8
  require "resource/consumer/mongoid"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-resource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Andr\xC3\xA9 Pankratz"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-16 00:00:00 +01:00
18
+ date: 2011-01-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency