vidibus-resource 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,16 @@
1
- = vidibus-resource
1
+ = Vidibus::Resource
2
2
 
3
3
  Description goes here.
4
4
 
5
+
6
+ == TODO
7
+
8
+ * Write specs
9
+ * Allow an individual provider for each resource. Store resource provider and realm on consumer instance.
10
+ * Don't allow resource consumers without a realm. Ensure realm matches request.
11
+ * Allow multiple providers for one resource?
12
+
13
+
5
14
  == Copyright
6
15
 
7
16
  Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
@@ -1,3 +1,4 @@
1
+ # TODO: Split this file: one part for providers, one for consumers?
1
2
  class Api::ResourcesController < ApiController
2
3
  before_filter :ensure_klass
3
4
  before_filter :find_instance
@@ -5,7 +6,7 @@ class Api::ResourcesController < ApiController
5
6
  # Creates resource consumer on provider.
6
7
  def create
7
8
  @instance.add_resource_consumer(params["service"])
8
- render :json => {:resource => @instance.fixed_resourceable_hash}
9
+ render(:json => {:resource => @instance.fixed_resourceable_hash})
9
10
  end
10
11
 
11
12
  # Updates resource on consumer.
@@ -15,27 +16,28 @@ class Api::ResourcesController < ApiController
15
16
  render :nothing => true
16
17
  rescue => e
17
18
  Rails.logger.error 'Error while updating resource consumer: '+e.inspect
18
- render :json => { :error => e }, :status => :bad_request
19
+ render(:json => {:error => e}, :status => :bad_request)
19
20
  end
20
21
  end
21
22
 
22
23
  # Removes a resource consumer from provider
24
+ # or remove a resource from a consumer.
23
25
  def destroy
24
- if @instance.resource_provider?
26
+ if @instance.respond_to?(:resource_consumers)
25
27
  @instance.remove_resource_consumer(params["service"])
26
28
  else
27
- # TODO
29
+ @instance.destroy_without_callback
28
30
  end
29
31
  render :nothing => true
30
32
  end
31
33
 
32
- protected
34
+ private
33
35
 
34
36
  def ensure_klass
35
37
  begin
36
38
  @klass = params[:klass].classify.constantize
37
39
  rescue => e
38
- render :json => { :error => e }, :status => :bad_request
40
+ render :json => {:error => e}, :status => :bad_request
39
41
  end
40
42
  end
41
43
 
@@ -44,6 +46,6 @@ class Api::ResourcesController < ApiController
44
46
  if @klass.new.respond_to?(:realm_uuid)
45
47
  result.and(:realm_uuid => params[:realm])
46
48
  end
47
- @instance = result.first or render(:nothing => true, :status => :not_found)
49
+ @instance = result.first or render(:json => {:error => "#{@klass} #{params[:uuid]} not found"}, :status => :not_found)
48
50
  end
49
51
  end
@@ -14,9 +14,11 @@ module Vidibus::Resource
14
14
  index :uuid
15
15
  validates :uuid, :uuid => true
16
16
 
17
+ attr_accessor :extinct
18
+
17
19
  before_create :add_resource_consumer
18
20
  before_save :set_resource_attributes
19
- before_destroy :remove_resource_consumer
21
+ before_destroy :remove_resource_consumer, :unless => :extinct
20
22
  end
21
23
 
22
24
  # Registers this consumer with provider.
@@ -90,7 +92,12 @@ module Vidibus::Resource
90
92
  true # ensure true!
91
93
  end
92
94
 
93
- protected
95
+ def destroy_without_callback
96
+ self.extinct = true
97
+ destroy
98
+ end
99
+
100
+ private
94
101
 
95
102
  # Fix empty arrays
96
103
  def fix_resource_attributes(data)
@@ -10,7 +10,7 @@ module Vidibus::Resource
10
10
  field :resourceable_hash_checksum, :type => Hash
11
11
 
12
12
  before_update :update_resource_consumers
13
- # before_destroy :destroy_resource_consumers
13
+ before_destroy :destroy_resource_consumers
14
14
  end
15
15
 
16
16
  # Adds given resource consumer.
@@ -49,7 +49,7 @@ module Vidibus::Resource
49
49
  resourceable_hash
50
50
  end
51
51
 
52
- protected
52
+ private
53
53
 
54
54
  # Update resource consumers if significant changes were made.
55
55
  # TODO: Send changes only (the resourceable ones)!
@@ -72,6 +72,20 @@ module Vidibus::Resource
72
72
  end
73
73
  end
74
74
  end
75
+
76
+ # Removes this resource from consumers.
77
+ def destroy_resource_consumers
78
+ for service in resource_consumers
79
+ begin
80
+ ::Service.discover(service, realm_uuid).delete("/api/resources/#{self.class.to_s.tableize}/#{uuid}")
81
+ rescue => e
82
+ Rails.logger.error "An error occurred while destroying resource consumer #{service}:"
83
+ Rails.logger.error e.inspect
84
+ errors = true
85
+ end
86
+ end
87
+ true unless errors # ensure true!
88
+ end
75
89
  end
76
90
  end
77
91
  end
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Resource
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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-05-04 00:00:00 +02:00
18
+ date: 2011-05-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -176,7 +176,6 @@ extra_rdoc_files: []
176
176
  files:
177
177
  - .gitignore
178
178
  - Gemfile
179
- - Gemfile.lock
180
179
  - LICENSE
181
180
  - README.rdoc
182
181
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,138 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- vidibus-resource (0.0.1)
5
- rails (~> 3.0.0)
6
- vidibus-api
7
- vidibus-service
8
- vidibus-uuid
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- abstract (1.0.0)
14
- actionmailer (3.0.3)
15
- actionpack (= 3.0.3)
16
- mail (~> 2.2.9)
17
- actionpack (3.0.3)
18
- activemodel (= 3.0.3)
19
- activesupport (= 3.0.3)
20
- builder (~> 2.1.2)
21
- erubis (~> 2.6.6)
22
- i18n (~> 0.4)
23
- rack (~> 1.2.1)
24
- rack-mount (~> 0.6.13)
25
- rack-test (~> 0.5.6)
26
- tzinfo (~> 0.3.23)
27
- activemodel (3.0.3)
28
- activesupport (= 3.0.3)
29
- builder (~> 2.1.2)
30
- i18n (~> 0.4)
31
- activerecord (3.0.3)
32
- activemodel (= 3.0.3)
33
- activesupport (= 3.0.3)
34
- arel (~> 2.0.2)
35
- tzinfo (~> 0.3.23)
36
- activeresource (3.0.3)
37
- activemodel (= 3.0.3)
38
- activesupport (= 3.0.3)
39
- activesupport (3.0.3)
40
- arel (2.0.7)
41
- bson (1.1.5)
42
- builder (2.1.2)
43
- crack (0.1.8)
44
- diff-lcs (1.1.2)
45
- erubis (2.6.6)
46
- abstract (>= 1.0.0)
47
- httparty (0.6.1)
48
- crack (= 0.1.8)
49
- i18n (0.5.0)
50
- json (1.4.6)
51
- macaddr (1.0.0)
52
- mail (2.2.14)
53
- activesupport (>= 2.3.6)
54
- i18n (>= 0.4.0)
55
- mime-types (~> 1.16)
56
- treetop (~> 1.4.8)
57
- mime-types (1.16)
58
- mongo (1.1.5)
59
- bson (>= 1.1.5)
60
- mongoid (2.0.0.rc.4)
61
- activemodel (~> 3.0)
62
- mongo (~> 1.1.5)
63
- tzinfo (~> 0.3.22)
64
- will_paginate (~> 3.0.pre)
65
- polyglot (0.3.1)
66
- rack (1.2.1)
67
- rack-mount (0.6.13)
68
- rack (>= 1.0.0)
69
- rack-test (0.5.7)
70
- rack (>= 1.0)
71
- rails (3.0.3)
72
- actionmailer (= 3.0.3)
73
- actionpack (= 3.0.3)
74
- activerecord (= 3.0.3)
75
- activeresource (= 3.0.3)
76
- activesupport (= 3.0.3)
77
- bundler (~> 1.0)
78
- railties (= 3.0.3)
79
- railties (3.0.3)
80
- actionpack (= 3.0.3)
81
- activesupport (= 3.0.3)
82
- rake (>= 0.8.7)
83
- thor (~> 0.14.4)
84
- rake (0.8.7)
85
- rr (1.0.2)
86
- rspec (2.0.1)
87
- rspec-core (~> 2.0.1)
88
- rspec-expectations (~> 2.0.1)
89
- rspec-mocks (~> 2.0.1)
90
- rspec-core (2.0.1)
91
- rspec-expectations (2.0.1)
92
- diff-lcs (>= 1.1.2)
93
- rspec-mocks (2.0.1)
94
- rspec-core (~> 2.0.1)
95
- rspec-expectations (~> 2.0.1)
96
- thor (0.14.6)
97
- treetop (1.4.9)
98
- polyglot (>= 0.3.1)
99
- tzinfo (0.3.24)
100
- uuid (2.3.1)
101
- macaddr (~> 1.0)
102
- vidibus-api (0.0.1)
103
- vidibus-service
104
- vidibus-core_extensions (0.3.15)
105
- vidibus-secure (0.0.3)
106
- activesupport (~> 3.0.0)
107
- mongoid (~> 2.0.0.beta.20)
108
- rack
109
- vidibus-core_extensions
110
- vidibus-service (0.0.4)
111
- httparty
112
- json
113
- mongoid (~> 2.0.0.beta.20)
114
- vidibus-core_extensions
115
- vidibus-secure
116
- vidibus-uuid
117
- vidibus-validate_uri
118
- vidibus-uuid (0.3.8)
119
- mongoid (~> 2.0.0.beta.20)
120
- uuid (~> 2.3.1)
121
- vidibus-validate_uri (0.1.4)
122
- rails (~> 3.0.0)
123
- will_paginate (3.0.pre2)
124
-
125
- PLATFORMS
126
- ruby
127
-
128
- DEPENDENCIES
129
- bundler (>= 1.0.0)
130
- rack-test
131
- rails (~> 3.0.0)
132
- rake
133
- rr
134
- rspec
135
- vidibus-api
136
- vidibus-resource!
137
- vidibus-service
138
- vidibus-uuid