vidibus-resource 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Vidibus::Resource [![](http://stillmaintained.com/vidibus/vidibus-resource.png)](http://stillmaintained.com/vidibus/vidibus-resource)
2
+
3
+ Allows creation of proxy objects of remote resources on distributed applications.
4
+
5
+ This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed (video) applications.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add `gem "vidibus-resource"` to your Gemfile. Then call `bundle install` on your console.
11
+
12
+
13
+ ## Usage
14
+
15
+ DESCRIBE
16
+
17
+
18
+ ## Copyright
19
+
20
+ © 2011 Andre Pankratz. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,11 +1,13 @@
1
1
  require "bundler"
2
- Bundler::GemHelper.install_tasks
3
-
4
- require "rake"
5
2
  require "rdoc/task"
6
3
  require "rspec"
7
4
  require "rspec/core/rake_task"
8
5
 
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
9
+ require "vidibus/resource/version"
10
+
9
11
  RSpec::Core::RakeTask.new(:rcov) do |t|
10
12
  t.pattern = "spec/**/*_spec.rb"
11
13
  t.rcov = true
@@ -13,10 +15,11 @@ RSpec::Core::RakeTask.new(:rcov) do |t|
13
15
  end
14
16
 
15
17
  Rake::RDocTask.new do |rdoc|
16
- require File.expand_path("../lib/vidibus/resource/version", __FILE__)
17
18
  rdoc.rdoc_dir = "rdoc"
18
- rdoc.title = "vidibus-resource #{Vidibus::Resource::VERSION}"
19
+ rdoc.title = "vidibus-sysinfo #{Vidibus::Resource::VERSION}"
19
20
  rdoc.rdoc_files.include("README*")
20
21
  rdoc.rdoc_files.include("lib/**/*.rb")
21
22
  rdoc.options << "--charset=utf-8"
22
23
  end
24
+
25
+ task :default => :rcov
@@ -39,8 +39,7 @@ module Vidibus::Resource
39
39
  # Updates resource attributes.
40
40
  # TODO: Update only data that has been changed.
41
41
  def update_resource_attributes(data)
42
- data = fix_resource_attributes(data)
43
- update_attributes(:resource_attributes => data)
42
+ update_attributes(:resource_attributes => JSON.parse(data))
44
43
  end
45
44
 
46
45
  # Returns a resource provider service.
@@ -99,16 +98,6 @@ module Vidibus::Resource
99
98
 
100
99
  private
101
100
 
102
- # Fix empty arrays
103
- def fix_resource_attributes(data)
104
- for key, value in data
105
- if value === [EMPTY_ARRAY_IDENTIFIER]
106
- data[key] = []
107
- end
108
- end
109
- data
110
- end
111
-
112
101
  module ClassMethods
113
102
 
114
103
  # Sets up resource provider service type and realm.
@@ -39,16 +39,6 @@ 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
-
52
42
  private
53
43
 
54
44
  # Update resource consumers if significant changes were made.
@@ -58,13 +48,14 @@ module Vidibus::Resource
58
48
  return unless resource_consumers and resource_consumers.any?
59
49
  return unless changes.except("resource_consumers", "updated_at").any?
60
50
 
61
- hash = fixed_resourceable_hash
51
+ hash = resourceable_hash
62
52
  hash_checksum = Digest::MD5.hexdigest(hash.to_s)
63
53
  unless hash_checksum == resourceable_hash_checksum
64
54
  self.resourceable_hash_checksum = hash_checksum
55
+ uri = "/api/resources/#{self.class.to_s.tableize}/#{uuid}"
65
56
  for service in resource_consumers
66
57
  begin
67
- ::Service.discover(service, realm_uuid).delay.put("/api/resources/#{self.class.to_s.tableize}/#{uuid}", :body => {:resource => hash})
58
+ ::Service.discover(service, realm_uuid).delay.put(uri, :body => {:resource => JSON.generate(hash)})
68
59
  rescue => e
69
60
  Rails.logger.error "An error occurred while updating resource consumer #{service}:"
70
61
  Rails.logger.error e.inspect
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Resource
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,8 +1,2 @@
1
- module Vidibus
2
- module Resource
3
- EMPTY_ARRAY_IDENTIFIER = "__r::array__"
4
- end
5
- end
6
-
7
- require "resource/provider/mongoid"
8
- require "resource/consumer/mongoid"
1
+ require "vidibus/resource/provider/mongoid"
2
+ require "vidibus/resource/consumer/mongoid"
@@ -1,10 +1,10 @@
1
+ require "json"
1
2
  require "rails"
2
3
  require "vidibus-uuid"
3
4
  require "vidibus-secure"
4
5
  require "vidibus-api"
5
6
 
6
- $:.unshift(File.join(File.dirname(__FILE__), "vidibus"))
7
- require "resource"
7
+ require "vidibus/resource"
8
8
 
9
9
  module Vidibus::Resource
10
10
  class Engine < ::Rails::Engine; end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-resource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
- - "Andr\xC3\xA9 Pankratz"
13
+ - Andre Pankratz
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-31 00:00:00 +02:00
18
+ date: 2011-07-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: vidibus-uuid
50
+ name: json
51
51
  prerelease: false
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :runtime
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: vidibus-service
64
+ name: vidibus-uuid
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :runtime
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: vidibus-api
78
+ name: vidibus-service
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
@@ -89,9 +89,23 @@ dependencies:
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
- name: delayed_job
92
+ name: vidibus-api
93
93
  prerelease: false
94
94
  requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: delayed_job
107
+ prerelease: false
108
+ requirement: &id007 !ruby/object:Gem::Requirement
95
109
  none: false
96
110
  requirements:
97
111
  - - ~>
@@ -102,11 +116,11 @@ dependencies:
102
116
  - 0
103
117
  version: "2.0"
104
118
  type: :runtime
105
- version_requirements: *id006
119
+ version_requirements: *id007
106
120
  - !ruby/object:Gem::Dependency
107
121
  name: delayed_job_mongoid
108
122
  prerelease: false
109
- requirement: &id007 !ruby/object:Gem::Requirement
123
+ requirement: &id008 !ruby/object:Gem::Requirement
110
124
  none: false
111
125
  requirements:
112
126
  - - ~>
@@ -117,11 +131,11 @@ dependencies:
117
131
  - 0
118
132
  version: "1.0"
119
133
  type: :runtime
120
- version_requirements: *id007
134
+ version_requirements: *id008
121
135
  - !ruby/object:Gem::Dependency
122
136
  name: bundler
123
137
  prerelease: false
124
- requirement: &id008 !ruby/object:Gem::Requirement
138
+ requirement: &id009 !ruby/object:Gem::Requirement
125
139
  none: false
126
140
  requirements:
127
141
  - - ">="
@@ -133,11 +147,11 @@ dependencies:
133
147
  - 0
134
148
  version: 1.0.0
135
149
  type: :development
136
- version_requirements: *id008
150
+ version_requirements: *id009
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: rake
139
153
  prerelease: false
140
- requirement: &id009 !ruby/object:Gem::Requirement
154
+ requirement: &id010 !ruby/object:Gem::Requirement
141
155
  none: false
142
156
  requirements:
143
157
  - - ">="
@@ -147,11 +161,11 @@ dependencies:
147
161
  - 0
148
162
  version: "0"
149
163
  type: :development
150
- version_requirements: *id009
164
+ version_requirements: *id010
151
165
  - !ruby/object:Gem::Dependency
152
- name: rspec
166
+ name: rdoc
153
167
  prerelease: false
154
- requirement: &id010 !ruby/object:Gem::Requirement
168
+ requirement: &id011 !ruby/object:Gem::Requirement
155
169
  none: false
156
170
  requirements:
157
171
  - - ">="
@@ -161,11 +175,11 @@ dependencies:
161
175
  - 0
162
176
  version: "0"
163
177
  type: :development
164
- version_requirements: *id010
178
+ version_requirements: *id011
165
179
  - !ruby/object:Gem::Dependency
166
- name: rack-test
180
+ name: rcov
167
181
  prerelease: false
168
- requirement: &id011 !ruby/object:Gem::Requirement
182
+ requirement: &id012 !ruby/object:Gem::Requirement
169
183
  none: false
170
184
  requirements:
171
185
  - - ">="
@@ -175,11 +189,25 @@ dependencies:
175
189
  - 0
176
190
  version: "0"
177
191
  type: :development
178
- version_requirements: *id011
192
+ version_requirements: *id012
193
+ - !ruby/object:Gem::Dependency
194
+ name: rspec
195
+ prerelease: false
196
+ requirement: &id013 !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ hash: 3
202
+ segments:
203
+ - 0
204
+ version: "0"
205
+ type: :development
206
+ version_requirements: *id013
179
207
  - !ruby/object:Gem::Dependency
180
208
  name: rr
181
209
  prerelease: false
182
- requirement: &id012 !ruby/object:Gem::Requirement
210
+ requirement: &id014 !ruby/object:Gem::Requirement
183
211
  none: false
184
212
  requirements:
185
213
  - - ">="
@@ -189,10 +217,23 @@ dependencies:
189
217
  - 0
190
218
  version: "0"
191
219
  type: :development
192
- version_requirements: *id012
220
+ version_requirements: *id014
221
+ - !ruby/object:Gem::Dependency
222
+ name: webmock
223
+ prerelease: false
224
+ requirement: &id015 !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ hash: 3
230
+ segments:
231
+ - 0
232
+ version: "0"
233
+ type: :development
234
+ version_requirements: *id015
193
235
  description: Allows creation of proxy objects of remote resources on distributed applications.
194
- email:
195
- - andre@vidibus.com
236
+ email: andre@vidibus.com
196
237
  executables: []
197
238
 
198
239
  extensions: []
@@ -200,21 +241,16 @@ extensions: []
200
241
  extra_rdoc_files: []
201
242
 
202
243
  files:
203
- - .gitignore
204
- - Gemfile
205
- - LICENSE
206
- - README.rdoc
207
- - Rakefile
208
- - app/controllers/api/resources_controller.rb
209
- - config/routes.rb
210
- - lib/vidibus-resource.rb
211
- - lib/vidibus/resource.rb
212
244
  - lib/vidibus/resource/consumer/mongoid.rb
213
245
  - lib/vidibus/resource/provider/mongoid.rb
214
246
  - lib/vidibus/resource/version.rb
215
- - spec/spec_helper.rb
216
- - spec/vidibus/resource/consumer/mongoid_spec.rb
217
- - vidibus-resource.gemspec
247
+ - lib/vidibus/resource.rb
248
+ - lib/vidibus-resource.rb
249
+ - app/controllers/api/resources_controller.rb
250
+ - config/routes.rb
251
+ - LICENSE
252
+ - README.md
253
+ - Rakefile
218
254
  has_rdoc: true
219
255
  homepage: https://github.com/vidibus/vidibus-resource
220
256
  licenses: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
4
- rdoc
5
- coverage
6
- Gemfile.lock
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source :gemcutter
2
-
3
- # Specify your gem's dependencies in vidibus-resource.gemspec
4
- gemspec
data/README.rdoc DELETED
@@ -1,16 +0,0 @@
1
- = Vidibus::Resource
2
-
3
- Description goes here.
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
-
14
- == Copyright
15
-
16
- Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
data/spec/spec_helper.rb DELETED
@@ -1,25 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require "rubygems"
5
- require "rspec"
6
- require "mongoid"
7
- require "rack/test"
8
- require "rr"
9
- # require "webmock/rspec"
10
- require "vidibus-resource"
11
-
12
- Mongoid.configure do |config|
13
- name = "vidibus-resource_test"
14
- host = "localhost"
15
- config.master = Mongo::Connection.new.db(name)
16
- config.logger = nil
17
- end
18
-
19
- RSpec.configure do |config|
20
- # config.include WebMock
21
- config.mock_with :rr
22
- config.before(:each) do
23
- Mongoid.master.collections.select {|c| c.name !~ /system/}.each(&:drop)
24
- end
25
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- class Model
4
- include Mongoid::Document
5
- include Vidibus::Resource::Consumer::Mongoid
6
- end
7
-
8
- describe "Vidibus::Resource::Consumer::Mongoid" do
9
-
10
- let(:model) do
11
- Model.new.tap do |m|
12
- m.resource_attributes = {"name" => "Jenny"}
13
- m.set_resource_attributes(true)
14
- end
15
- end
16
-
17
- describe "attributes" do
18
- it "should be readable" do
19
- model.name.should eql("Jenny")
20
- end
21
-
22
- it "should be writable" do
23
- model.name = "Sara"
24
- model.name.should eql("Sara")
25
- end
26
-
27
- it "should be persistent" do
28
- stub(model).add_resource_consumer
29
- stub(model).set_resource_attributes
30
- model.save
31
- model.update_attributes!({:name => "Sara"})
32
- model.reload
33
- model.name.should eql("Sara")
34
- end
35
- end
36
- end
@@ -1,34 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/vidibus/resource/version", __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "vidibus-resource"
6
- s.version = Vidibus::Resource::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["André Pankratz"]
9
- s.email = ["andre@vidibus.com"]
10
- s.homepage = "https://github.com/vidibus/vidibus-resource"
11
- s.summary = "Provides handling of remote resources"
12
- s.description = "Allows creation of proxy objects of remote resources on distributed applications."
13
-
14
- s.required_rubygems_version = ">= 1.3.6"
15
- s.rubyforge_project = "vidibus-resource"
16
-
17
- s.add_dependency "rails", "~> 3"
18
- s.add_dependency "mongoid", "~> 2"
19
- s.add_dependency "vidibus-uuid"
20
- s.add_dependency "vidibus-service"
21
- s.add_dependency "vidibus-api"
22
- s.add_dependency "delayed_job", "~> 2.0"
23
- s.add_dependency "delayed_job_mongoid", "~> 1.0"
24
-
25
- s.add_development_dependency "bundler", ">= 1.0.0"
26
- s.add_development_dependency "rake", ">= 0"
27
- s.add_development_dependency "rspec", ">= 0"
28
- s.add_development_dependency "rack-test", ">= 0"
29
- s.add_development_dependency "rr", ">= 0"
30
-
31
- s.files = `git ls-files`.split("\n")
32
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
33
- s.require_path = 'lib'
34
- end