acts_as_stream 0.0.2.alpha.1 → 0.0.2.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,10 +4,12 @@ require "acts_as_stream/configuration"
4
4
  require "acts_as_stream/connector"
5
5
  require "acts_as_stream/version"
6
6
  require 'acts_as_stream/streamable_object'
7
+ require 'acts_as_stream/stream_activity'
7
8
 
8
9
  module ActsAsStream
9
10
  extend Configuration
10
11
  extend Connector
12
+ extend StreamActivity
11
13
  end
12
14
 
13
15
  ActiveRecord::Base.send :include, ActsAsStream::StreamableObject
@@ -0,0 +1,30 @@
1
+ module ActsAsStream
2
+ module StreamActivity
3
+
4
+ def package options = {}
5
+ options.assert_valid_keys(:who, :action, :time, :object, :ignore_stream_hash_on)
6
+ raise "You need at least a :who and an :action! to create an activity package" if options[:who].nil? or options[:action].nil?
7
+ opts = {:time => Time.now.to_i, :ignore_stream_hash_on => []}.merge options
8
+ # Try to ensure :time is in seconds
9
+ opts[:time] = opts[:time].to_i if opts[:time].is_a?(Time)
10
+
11
+ # If Objects provide the :to_stream_hash method, use it.
12
+ if opts[:ignore_stream_hash_on].present?
13
+ #convenience, make sure it's an array so we can use include? instead of "include? or equals"
14
+ opts[:ignore_stream_hash_on] = [opts[:ignore_stream_hash_on]] unless opts[:ignore_stream_hash_on].is_a?(Array)
15
+ end
16
+
17
+ [:who, :object].each do |opt|
18
+ #unless we are ignoring the stream hash for this object, use StreamableObject.stream_hash
19
+ unless opts[:ignore_stream_hash_on].include?(opt)
20
+ opts[opt] = opts[opt].to_stream_hash
21
+ end
22
+ end
23
+
24
+ opts.delete(:ignore_stream_hash_on)
25
+
26
+ # then, if everything is fine, bundle it up into a JSON string
27
+ opts.to_json
28
+ end
29
+ end
30
+ end
@@ -19,6 +19,9 @@ module ActsAsStream
19
19
 
20
20
  module InstanceMethods
21
21
 
22
+ def to_stream_hash
23
+ {self.class.name.tableize.singularize => {'id' => self.id, activity_attr.to_s => self.send(activity_attr)}}
24
+ end
22
25
  def activity_id
23
26
  self.send(self.class.activity_attr)
24
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsStream
2
- VERSION = "0.0.2.alpha.1"
2
+ VERSION = "0.0.2.alpha.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.alpha.1
4
+ version: 0.0.2.alpha.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70248699332900 !ruby/object:Gem::Requirement
16
+ requirement: &70308593724360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70248699332900
24
+ version_requirements: *70308593724360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70248699332100 !ruby/object:Gem::Requirement
27
+ requirement: &70308593723900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70248699332100
35
+ version_requirements: *70308593723900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70248699331420 !ruby/object:Gem::Requirement
38
+ requirement: &70308593723380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70248699331420
46
+ version_requirements: *70308593723380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: acts_as_amico
49
- requirement: &70248699330520 !ruby/object:Gem::Requirement
49
+ requirement: &70308593722800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70248699330520
57
+ version_requirements: *70308593722800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec-rails
60
- requirement: &70248699329720 !ruby/object:Gem::Requirement
60
+ requirement: &70308593722160 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70248699329720
68
+ version_requirements: *70308593722160
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: spork
71
- requirement: &70248699328140 !ruby/object:Gem::Requirement
71
+ requirement: &70308593747820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.0.rc
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70248699328140
79
+ version_requirements: *70308593747820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &70248699343560 !ruby/object:Gem::Requirement
82
+ requirement: &70308593746680 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70248699343560
90
+ version_requirements: *70308593746680
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-spork
93
- requirement: &70248699342760 !ruby/object:Gem::Requirement
93
+ requirement: &70308593744540 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70248699342760
101
+ version_requirements: *70308593744540
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: factory_girl_rails
104
- requirement: &70248699342180 !ruby/object:Gem::Requirement
104
+ requirement: &70308593743920 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70248699342180
112
+ version_requirements: *70308593743920
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &70248699340840 !ruby/object:Gem::Requirement
115
+ requirement: &70308593743200 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70248699340840
123
+ version_requirements: *70308593743200
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: fakeweb
126
- requirement: &70248699339860 !ruby/object:Gem::Requirement
126
+ requirement: &70308593742600 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70248699339860
134
+ version_requirements: *70308593742600
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: uuidtools
137
- requirement: &70248699338500 !ruby/object:Gem::Requirement
137
+ requirement: &70308593741800 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70248699338500
145
+ version_requirements: *70308593741800
146
146
  description: Rails injectable Redis-backed activity stream system. This is an alpha
147
147
  release of code that I just wrote and put into production on 3/11/12. Send feedback
148
148
  and post bugs to the Github page, but use at your own risk!
@@ -154,6 +154,7 @@ extra_rdoc_files: []
154
154
  files:
155
155
  - lib/acts_as_stream/configuration.rb
156
156
  - lib/acts_as_stream/connector.rb
157
+ - lib/acts_as_stream/stream_activity.rb
157
158
  - lib/acts_as_stream/streamable_object.rb
158
159
  - lib/acts_as_stream/version.rb
159
160
  - lib/acts_as_stream.rb