custom_streams 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -2
- data/Rakefile +9 -1
- data/custom_streams.gemspec +1 -0
- data/lib/custom_streams/activity.rb +1 -1
- data/lib/custom_streams/generator.rb +12 -0
- data/lib/custom_streams/railtie.rb +7 -0
- data/lib/custom_streams/streamer.rb +4 -4
- data/lib/custom_streams/version.rb +1 -1
- data/lib/custom_streams.rb +6 -3
- data/spec/custom_streams_spec.rb +2 -2
- data/templates/activities.rb +4 -4
- metadata +21 -3
data/README.md
CHANGED
@@ -13,12 +13,17 @@ And then execute:
|
|
13
13
|
|
14
14
|
$ bundle
|
15
15
|
|
16
|
-
|
16
|
+
Run the installer:
|
17
17
|
|
18
|
-
|
18
|
+
rails g custom_streams:install
|
19
|
+
|
20
|
+
And then run the generated migration:
|
21
|
+
|
22
|
+
rake db:migrate
|
19
23
|
|
20
24
|
## Usage
|
21
25
|
|
26
|
+
|
22
27
|
## Contributing
|
23
28
|
|
24
29
|
1. Fork it
|
data/Rakefile
CHANGED
data/custom_streams.gemspec
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module CustomStreams
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.dirname(__FILE__) + "/../../templates"
|
6
|
+
|
7
|
+
def copy_migrations
|
8
|
+
stamp = proc {|time| time.utc.strftime("%Y%m%d%H%M%S")}
|
9
|
+
copy_file "activities.rb", "db/migrate/#{stamp[Time.now]}_create_activities.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -9,21 +9,21 @@ module CustomStreams
|
|
9
9
|
|
10
10
|
def streamer args={}
|
11
11
|
|
12
|
+
has_many :activities, as: :streamable
|
13
|
+
|
12
14
|
define_method :streamer_options do
|
13
15
|
args
|
14
16
|
end
|
15
17
|
|
16
18
|
define_method :create_activity do |activity|
|
17
19
|
namespace = streamer_options.fetch(:namespace, nil)
|
18
|
-
p namespace
|
19
20
|
name = namespace ? "#{namespace}.#{activity}" : activity
|
20
|
-
|
21
|
-
Activity.create owner_id: self.id, owner_type: self.class.to_s, name: name
|
21
|
+
Activity.create streamable_id: self.id, streamable_type: self.class.to_s, name: name
|
22
22
|
end
|
23
23
|
|
24
24
|
define_method :stream do |args={}|
|
25
25
|
order = args.fetch(:order, 'created_at DESC')
|
26
|
-
|
26
|
+
self.activities.order(order)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/lib/custom_streams.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'active_record'
|
3
|
+
require 'custom_streams/version'
|
4
|
+
require 'custom_streams/streamer'
|
5
|
+
require 'custom_streams/activity'
|
6
|
+
require 'custom_streams/railtie'
|
4
7
|
|
5
8
|
module CustomStreams
|
6
9
|
end
|
data/spec/custom_streams_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Document do
|
|
11
11
|
document.create_activity("new_activity")
|
12
12
|
end
|
13
13
|
specify { Activity.count.should eq 1 }
|
14
|
-
specify { Activity.first.
|
15
|
-
specify { Activity.first.
|
14
|
+
specify { Activity.first.streamable_id.should eq document.id }
|
15
|
+
specify { Activity.first.streamable_type.should eq 'Document' }
|
16
16
|
specify { Activity.first.name.should eq 'new_activity' }
|
17
17
|
end
|
18
18
|
|
data/templates/activities.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
class CreateActivities < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :activities do |t|
|
4
|
-
t.integer :
|
5
|
-
t.string :
|
4
|
+
t.integer :streamable_id, :null => false
|
5
|
+
t.string :streamable_type, :name, :null => false
|
6
6
|
t.string :name, :null => false
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
9
|
|
10
|
-
add_index :activities, :
|
11
|
-
add_index :activities, :
|
10
|
+
add_index :activities, :streamable_type
|
11
|
+
add_index :activities, :streamable_id
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.down
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_streams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: bundler
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +123,8 @@ files:
|
|
107
123
|
- custom_streams.gemspec
|
108
124
|
- lib/custom_streams.rb
|
109
125
|
- lib/custom_streams/activity.rb
|
126
|
+
- lib/custom_streams/generator.rb
|
127
|
+
- lib/custom_streams/railtie.rb
|
110
128
|
- lib/custom_streams/streamer.rb
|
111
129
|
- lib/custom_streams/version.rb
|
112
130
|
- spec/custom_streams_spec.rb
|
@@ -128,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
146
|
version: '0'
|
129
147
|
segments:
|
130
148
|
- 0
|
131
|
-
hash:
|
149
|
+
hash: 2472144999673379205
|
132
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
151
|
none: false
|
134
152
|
requirements:
|
@@ -137,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
155
|
version: '0'
|
138
156
|
segments:
|
139
157
|
- 0
|
140
|
-
hash:
|
158
|
+
hash: 2472144999673379205
|
141
159
|
requirements: []
|
142
160
|
rubyforge_project:
|
143
161
|
rubygems_version: 1.8.25
|