bustle 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -163,6 +163,19 @@ Bustle::Publishers.get(publisher).destroy
163
163
  Bustle::Subscriptions.get(bustle_publisher, bustle_subscriber).destroy
164
164
  ```
165
165
 
166
+ #### Find Referenced Resources
167
+
168
+ These are helpful for finding referenced resources.
169
+
170
+ ```ruby
171
+ Bustle::Activity#publisher_resource
172
+ Bustle::Activity#target_resource
173
+ Bustle::Publisher#target_resource
174
+ Bustle::Subscriber#target_resource
175
+ Bustle::Subscription#publisher_resource
176
+ Bustle::Subscription#subscriber_resource
177
+ ```
178
+
166
179
  #### Publish an Activity
167
180
 
168
181
  ```ruby
@@ -0,0 +1,10 @@
1
+ module Bustle::Concern
2
+ module PublisherResource
3
+ extend ActiveSupport::Concern
4
+
5
+ def publisher_resource
6
+ publisher = Bustle::Publisher.to_adapter.get!(self.publisher_id)
7
+ publisher.resource_class.constantize.to_adapter.get!(publisher.resource_id)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Bustle::Concern
2
+ module SubscriberResource
3
+ extend ActiveSupport::Concern
4
+
5
+ def subscriber_resource
6
+ subscriber = Bustle::Subscriber.to_adapter.get!(self.subscriber_id)
7
+ subscriber.resource_class.constantize.to_adapter.get!(subscriber.resource_id)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Bustle::Concern
2
+ module TargetResource
3
+ extend ActiveSupport::Concern
4
+
5
+ def target_resource
6
+ self.resource_class.constantize.to_adapter.get!(self.resource_id)
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,6 @@
1
1
  module Bustle
2
2
  class Activity < "#{Bustle.storage}::Activity".constantize
3
+ include Concern::TargetResource
4
+ include Concern::PublisherResource
3
5
  end
4
6
  end
@@ -1,5 +1,7 @@
1
1
  module Bustle
2
2
  class Publisher < "#{Bustle.storage}::Publisher".constantize
3
+ include Concern::TargetResource
4
+
3
5
  def publish(data = {})
4
6
  Activities.add(self, data)
5
7
  end
@@ -1,5 +1,7 @@
1
1
  module Bustle
2
2
  class Subscriber < "#{Bustle.storage}::Subscriber".constantize
3
+ include Concern::TargetResource
4
+
3
5
  def activities(conditions = {})
4
6
  Activities.for(self, conditions)
5
7
  end
@@ -1,4 +1,6 @@
1
1
  module Bustle
2
2
  class Subscription < "#{Bustle.storage}::Subscription".constantize
3
+ include Concern::PublisherResource
4
+ include Concern::SubscriberResource
3
5
  end
4
6
  end
@@ -1,3 +1,3 @@
1
1
  module Bustle
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/bustle.rb CHANGED
@@ -6,6 +6,9 @@ require "bustle/concerns/filterable"
6
6
  require "bustle/concerns/by_publisher"
7
7
  require "bustle/concerns/for_subscriber"
8
8
  require "bustle/concerns/resource_collection"
9
+ require "bustle/concerns/publisher_resource"
10
+ require "bustle/concerns/subscriber_resource"
11
+ require "bustle/concerns/target_resource"
9
12
  require "bustle/activities"
10
13
  require "bustle/publishers"
11
14
  require "bustle/subscribers"
@@ -5,5 +5,7 @@ module Bustle
5
5
  let(:described_class) { Activity }
6
6
 
7
7
  it_behaves_like 'model'
8
+ it_behaves_like 'publisher_resource'
9
+ it_behaves_like 'target_resource'
8
10
  end
9
11
  end
@@ -6,6 +6,7 @@ module Bustle
6
6
 
7
7
  include_context 'app_resources'
8
8
  it_behaves_like 'model'
9
+ it_behaves_like 'target_resource'
9
10
  it_behaves_like 'has_activities'
10
11
 
11
12
  it "is able to publish an activity" do
@@ -6,6 +6,7 @@ module Bustle
6
6
 
7
7
  include_context 'app_resources'
8
8
  it_behaves_like 'model'
9
+ it_behaves_like 'target_resource'
9
10
  it_behaves_like 'has_activities'
10
11
  end
11
12
  end
@@ -5,5 +5,7 @@ module Bustle
5
5
  let(:described_class) { Subscription }
6
6
 
7
7
  it_behaves_like 'model'
8
+ it_behaves_like 'publisher_resource'
9
+ it_behaves_like 'subscriber_resource'
8
10
  end
9
11
  end
@@ -0,0 +1,17 @@
1
+ shared_examples '_pubsub_resource' do
2
+ context "pubsub_resource" do
3
+ let(:pubsub_resource) { Bustle::Dummy::User.create! :name => 'Fred' }
4
+ let(:factory_class) { described_class }
5
+ let(:factory_name) { factory_class.to_s.split('::').last.downcase.to_sym }
6
+
7
+ let(:record) do
8
+ resource = pubsub_class.add pubsub_resource
9
+ create factory_name,
10
+ "#{pubsub_type}_id" => resource.id
11
+ end
12
+
13
+ it "references the resource" do
14
+ record.send("#{pubsub_type}_resource").should == pubsub_resource
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ shared_examples 'publisher_resource' do
2
+ let(:pubsub_class) { Bustle::Publishers }
3
+ let(:pubsub_type) { 'publisher' }
4
+
5
+ it_behaves_like '_pubsub_resource'
6
+ end
@@ -0,0 +1,6 @@
1
+ shared_examples 'subscriber_resource' do
2
+ let(:pubsub_class) { Bustle::Subscribers }
3
+ let(:pubsub_type) { 'subscriber' }
4
+
5
+ it_behaves_like '_pubsub_resource'
6
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples 'target_resource' do
2
+ context "target_resource" do
3
+ let(:target_resource) { Bustle::Dummy::User.create! :name => 'Fred' }
4
+ let(:factory_class) { described_class }
5
+ let(:factory_name) { factory_class.to_s.split('::').last.downcase.to_sym }
6
+
7
+ let(:record) do
8
+ create factory_name,
9
+ :resource_class => target_resource.class.name,
10
+ :resource_id => target_resource.id
11
+ end
12
+
13
+ it "references the target resource" do
14
+ record.target_resource.should == target_resource
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bustle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-04 00:00:00.000000000 Z
12
+ date: 2012-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -190,7 +190,10 @@ files:
190
190
  - lib/bustle/concerns/by_publisher.rb
191
191
  - lib/bustle/concerns/filterable.rb
192
192
  - lib/bustle/concerns/for_subscriber.rb
193
+ - lib/bustle/concerns/publisher_resource.rb
193
194
  - lib/bustle/concerns/resource_collection.rb
195
+ - lib/bustle/concerns/subscriber_resource.rb
196
+ - lib/bustle/concerns/target_resource.rb
194
197
  - lib/bustle/models/activity.rb
195
198
  - lib/bustle/models/publisher.rb
196
199
  - lib/bustle/models/subscriber.rb
@@ -217,9 +220,13 @@ files:
217
220
  - spec/spec_helper.rb
218
221
  - spec/support/active_record_tables.rb
219
222
  - spec/support/shared_context/app_resources.rb
223
+ - spec/support/shared_examples/_pubsub_resource.rb
220
224
  - spec/support/shared_examples/has_activities.rb
221
225
  - spec/support/shared_examples/model.rb
226
+ - spec/support/shared_examples/publisher_resource.rb
222
227
  - spec/support/shared_examples/resource_collection.rb
228
+ - spec/support/shared_examples/subscriber_resource.rb
229
+ - spec/support/shared_examples/target_resource.rb
223
230
  homepage: https://github.com/fredwu/bustle
224
231
  licenses: []
225
232
  post_install_message:
@@ -234,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
241
  version: '0'
235
242
  segments:
236
243
  - 0
237
- hash: -805955161985304810
244
+ hash: -1077479785842864960
238
245
  required_rubygems_version: !ruby/object:Gem::Requirement
239
246
  none: false
240
247
  requirements:
@@ -243,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
250
  version: '0'
244
251
  segments:
245
252
  - 0
246
- hash: -805955161985304810
253
+ hash: -1077479785842864960
247
254
  requirements: []
248
255
  rubyforge_project:
249
256
  rubygems_version: 1.8.24
@@ -264,6 +271,10 @@ test_files:
264
271
  - spec/spec_helper.rb
265
272
  - spec/support/active_record_tables.rb
266
273
  - spec/support/shared_context/app_resources.rb
274
+ - spec/support/shared_examples/_pubsub_resource.rb
267
275
  - spec/support/shared_examples/has_activities.rb
268
276
  - spec/support/shared_examples/model.rb
277
+ - spec/support/shared_examples/publisher_resource.rb
269
278
  - spec/support/shared_examples/resource_collection.rb
279
+ - spec/support/shared_examples/subscriber_resource.rb
280
+ - spec/support/shared_examples/target_resource.rb