my_feeds 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +4 -4
- data/lib/generators/my_feeds/likes_generator.rb +23 -0
- data/lib/generators/my_feeds_generator.rb +22 -0
- data/lib/{rails/generators/templates/model.rb → generators/templates/feed.rb} +1 -1
- data/lib/{rails/generators/templates/migration.rb → generators/templates/feeds_migration.rb} +2 -2
- data/lib/{rails/generators/templates/like_model.rb → generators/templates/like.rb} +0 -0
- data/lib/{rails/generators → generators}/templates/likes_migration.rb +2 -2
- data/lib/my_feeds.rb +2 -2
- data/lib/my_feeds/eater.rb +1 -1
- data/lib/my_feeds/identity.rb +39 -0
- data/lib/my_feeds/version.rb +1 -1
- data/my_feeds.gemspec +1 -1
- data/spec/models/feed.rb +1 -1
- data/spec/models/like.rb +2 -1
- data/spec/schema.rb +3 -3
- metadata +18 -18
- data/lib/my_feeds/identify.rb +0 -43
- data/lib/rails/generators/my_feeds/likes_generator.rb +0 -29
- data/lib/rails/generators/my_feeds_generator.rb +0 -28
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -47,15 +47,15 @@ and
|
|
47
47
|
```
|
48
48
|
class YourCustomModel < ActiveRecord::Base
|
49
49
|
include MyFeeds::Associate #make sure include this module
|
50
|
-
|
50
|
+
init_feeds_polymorphic = :likeable #and set this, in this case is likeable, it should same as the polymorphic belongs_to
|
51
51
|
|
52
|
-
#same as
|
52
|
+
#same as feeds_polymorphic
|
53
53
|
belongs_to :likeable, polymorphic: true
|
54
54
|
end
|
55
55
|
|
56
56
|
# you should create a migration like below
|
57
|
-
# in this case, this column name is
|
58
|
-
#add_column :your_customs, :
|
57
|
+
# in this case, this column name is likeable_identity, it depends on feeds_polymorphic
|
58
|
+
#add_column :your_customs, :likeable_identity, :string, null: false
|
59
59
|
```
|
60
60
|
|
61
61
|
####feeder
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module MyFeeds
|
4
|
+
module Generators
|
5
|
+
class LikesGenerator < ActiveRecord::Generators::Base
|
6
|
+
|
7
|
+
argument :name, :type => :string, :default => 'likes'
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
@source_root ||= File.join(File.dirname(__FILE__), '../templates')
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_migration
|
14
|
+
migration_template 'likes_migration.rb', 'db/migrate/likes_migration.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_model
|
18
|
+
template "like.rb", File.join('app/models', "like.rb")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module MyFeeds
|
4
|
+
module Generators
|
5
|
+
class MyFeedsGenerator < ActiveRecord::Generators::Base
|
6
|
+
|
7
|
+
argument :name, :type => :string, :default => 'my_feeds'
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_migration
|
14
|
+
migration_template 'feeds_migration.rb', 'db/migrate/my_feeds_migration.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_model
|
18
|
+
template "feed.rb", File.join('app/models', "feed.rb")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/{rails/generators/templates/migration.rb → generators/templates/feeds_migration.rb}
RENAMED
@@ -3,7 +3,7 @@ class MyFeedsMigration < ActiveRecord::Migration
|
|
3
3
|
create_table :feeds do |t|
|
4
4
|
#necessarily
|
5
5
|
t.references :source, :polymorphic => true, :null => false
|
6
|
-
t.string :
|
6
|
+
t.string :source_identity, null: false
|
7
7
|
t.string :event, null: false
|
8
8
|
|
9
9
|
#not necessarily, but maybe you need
|
@@ -13,6 +13,6 @@ class MyFeedsMigration < ActiveRecord::Migration
|
|
13
13
|
t.timestamps
|
14
14
|
end
|
15
15
|
|
16
|
-
add_index :feeds, :
|
16
|
+
add_index :feeds, :source_identity
|
17
17
|
end
|
18
18
|
end
|
File without changes
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class LikesMigration < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :likes do |t|
|
4
|
-
#this table must have
|
5
|
-
t.string :
|
4
|
+
#this table must have xxx_identity, xxx_id, xxx_type 3 columns
|
5
|
+
t.string :likeable_identity, null: false
|
6
6
|
t.references :likeable, :polymorphic => true, :null => false
|
7
7
|
|
8
8
|
#you maybe need change this column
|
data/lib/my_feeds.rb
CHANGED
@@ -3,8 +3,8 @@ require "my_feeds/version"
|
|
3
3
|
module MyFeeds
|
4
4
|
autoload :Feeder, 'my_feeds/feeder'
|
5
5
|
autoload :Eater, 'my_feeds/eater'
|
6
|
-
autoload :
|
6
|
+
autoload :Identity, 'my_feeds/identity'
|
7
7
|
|
8
8
|
#alias
|
9
|
-
Associate =
|
9
|
+
Associate = Identity
|
10
10
|
end
|
data/lib/my_feeds/eater.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module MyFeeds
|
2
|
+
module Identity
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_save :save_feed_identity
|
7
|
+
init_feeds_polymorphic :source if self == Feed
|
8
|
+
delegate :polymorphic_identity_column, :polymorphic_id_column, :polymorphic_type_column, to: :"self.class"
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def feed_polymorphic
|
13
|
+
@_feed_polymorphic
|
14
|
+
end
|
15
|
+
|
16
|
+
def init_feeds_polymorphic polymorphic
|
17
|
+
@_feed_polymorphic = polymorphic
|
18
|
+
class_eval %Q{
|
19
|
+
def save_feed_identity
|
20
|
+
self.#{polymorphic_identity_column} = "#\{#{polymorphic_id_column}.to_s\}:#\{#{polymorphic_type_column}.to_s.underscore\}"
|
21
|
+
end
|
22
|
+
protected :save_feed_identity
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def polymorphic_identity_column
|
27
|
+
:"#{feed_polymorphic}_identity"
|
28
|
+
end
|
29
|
+
|
30
|
+
def polymorphic_id_column
|
31
|
+
:"#{feed_polymorphic}_id"
|
32
|
+
end
|
33
|
+
|
34
|
+
def polymorphic_type_column
|
35
|
+
:"#{feed_polymorphic}_type"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/my_feeds/version.rb
CHANGED
data/my_feeds.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = MyFeeds::VERSION
|
9
9
|
spec.authors = ["jjy"]
|
10
10
|
spec.email = ["jjyruby@gmail.com"]
|
11
|
-
spec.description = %q{Help you implement feeds / timeline in rails application.}
|
11
|
+
spec.description = %q{Help you implement feeds / timeline / public activity in rails application.}
|
12
12
|
spec.summary = %q{my_feeds provide feed model and some helper methods, allow you to customize.}
|
13
13
|
spec.homepage = "https://github.com/jjyr/my_feeds"
|
14
14
|
spec.license = "MIT"
|
data/spec/models/feed.rb
CHANGED
data/spec/models/like.rb
CHANGED
data/spec/schema.rb
CHANGED
@@ -3,7 +3,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
3
3
|
create_table "feeds", :force => true do |t|
|
4
4
|
t.integer "source_id", :null => false
|
5
5
|
t.string "source_type", :null => false
|
6
|
-
t.string "
|
6
|
+
t.string "source_identity", :null => false
|
7
7
|
t.string "event", :null => false
|
8
8
|
t.integer "target_id"
|
9
9
|
t.string "target_type"
|
@@ -11,10 +11,10 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
11
11
|
t.datetime "updated_at", :null => false
|
12
12
|
end
|
13
13
|
|
14
|
-
add_index "feeds", ["
|
14
|
+
add_index "feeds", ["source_identity"], :name => "index_feeds_on_source_identity"
|
15
15
|
|
16
16
|
create_table "likes", :force => true do |t|
|
17
|
-
t.string "
|
17
|
+
t.string "likeable_identity", :null => false
|
18
18
|
t.integer "likeable_id", :null => false
|
19
19
|
t.string "likeable_type", :null => false
|
20
20
|
t.integer "user_id"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_feeds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,41 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
17
18
|
requirements:
|
18
19
|
- - ~>
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: '1.3'
|
21
|
-
none: false
|
22
|
-
prerelease: false
|
23
22
|
type: :development
|
23
|
+
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
29
|
version: '1.3'
|
29
|
-
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rake
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
33
34
|
requirements:
|
34
35
|
- - ! '>='
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: '0'
|
37
|
-
none: false
|
38
|
-
prerelease: false
|
39
38
|
type: :development
|
39
|
+
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
41
42
|
requirements:
|
42
43
|
- - ! '>='
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: '0'
|
45
|
-
|
46
|
-
description: Help you implement feeds / timeline in rails application.
|
46
|
+
description: Help you implement feeds / timeline / public activity in rails application.
|
47
47
|
email:
|
48
48
|
- jjyruby@gmail.com
|
49
49
|
executables: []
|
@@ -55,17 +55,17 @@ files:
|
|
55
55
|
- LICENSE.txt
|
56
56
|
- README.md
|
57
57
|
- Rakefile
|
58
|
+
- lib/generators/my_feeds/likes_generator.rb
|
59
|
+
- lib/generators/my_feeds_generator.rb
|
60
|
+
- lib/generators/templates/feed.rb
|
61
|
+
- lib/generators/templates/feeds_migration.rb
|
62
|
+
- lib/generators/templates/like.rb
|
63
|
+
- lib/generators/templates/likes_migration.rb
|
58
64
|
- lib/my_feeds.rb
|
59
65
|
- lib/my_feeds/eater.rb
|
60
66
|
- lib/my_feeds/feeder.rb
|
61
|
-
- lib/my_feeds/
|
67
|
+
- lib/my_feeds/identity.rb
|
62
68
|
- lib/my_feeds/version.rb
|
63
|
-
- lib/rails/generators/my_feeds/likes_generator.rb
|
64
|
-
- lib/rails/generators/my_feeds_generator.rb
|
65
|
-
- lib/rails/generators/templates/like_model.rb
|
66
|
-
- lib/rails/generators/templates/likes_migration.rb
|
67
|
-
- lib/rails/generators/templates/migration.rb
|
68
|
-
- lib/rails/generators/templates/model.rb
|
69
69
|
- my_feeds.gemspec
|
70
70
|
- spec/models/feed.rb
|
71
71
|
- spec/models/like.rb
|
@@ -82,17 +82,17 @@ rdoc_options: []
|
|
82
82
|
require_paths:
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
85
86
|
requirements:
|
86
87
|
- - ! '>='
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
|
-
none: false
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
91
92
|
requirements:
|
92
93
|
- - ! '>='
|
93
94
|
- !ruby/object:Gem::Version
|
94
95
|
version: '0'
|
95
|
-
none: false
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 1.8.25
|
data/lib/my_feeds/identify.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module MyFeeds
|
2
|
-
module Identify
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
before_save :save_feed_identify
|
7
|
-
self.feed_polymorphic = self == Feed ? :source : default_feed_polymorphic
|
8
|
-
delegate :default_feed_polymorphic, :polymorphic_identify_column, :polymorphic_id_column, :polymorphic_type_column, to: :"self.class"
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def feed_polymorphic
|
13
|
-
@_feed_polymorphic
|
14
|
-
end
|
15
|
-
|
16
|
-
def feed_polymorphic= polymorphic
|
17
|
-
@_feed_polymorphic = polymorphic
|
18
|
-
class_eval %Q{
|
19
|
-
def save_feed_identify
|
20
|
-
self.#{polymorphic_identify_column} = "#\{#{polymorphic_id_column}.to_s\}@#\{#{polymorphic_type_column}.to_s.underscore\}"
|
21
|
-
end
|
22
|
-
protected :save_feed_identify
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def default_feed_polymorphic
|
27
|
-
self.to_s.underscore
|
28
|
-
end
|
29
|
-
|
30
|
-
def polymorphic_identify_column
|
31
|
-
:"#{feed_polymorphic}_identify"
|
32
|
-
end
|
33
|
-
|
34
|
-
def polymorphic_id_column
|
35
|
-
:"#{feed_polymorphic}_id"
|
36
|
-
end
|
37
|
-
|
38
|
-
def polymorphic_type_column
|
39
|
-
:"#{feed_polymorphic}_type"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module MyFeeds
|
2
|
-
module Generators
|
3
|
-
class LikesGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
include Rails::Generators::Migration
|
6
|
-
|
7
|
-
def self.source_root
|
8
|
-
@source_root ||= File.join(File.dirname(__FILE__), '../templates')
|
9
|
-
end
|
10
|
-
|
11
|
-
def create_migration_file
|
12
|
-
migration_template 'likes_migration.rb', 'db/migrate/likes_migration.rb'
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.next_migration_number(dirname)
|
16
|
-
if ActiveRecord::Base.timestamped_migrations
|
17
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
18
|
-
else
|
19
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_model
|
24
|
-
template "like_model.rb", File.join('app/models', "like.rb")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module MyFeeds
|
2
|
-
module Generators
|
3
|
-
class MyFeedsGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
include Rails::Generators::Migration
|
6
|
-
|
7
|
-
def self.source_root
|
8
|
-
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
-
end
|
10
|
-
|
11
|
-
def create_migration_file
|
12
|
-
migration_template 'migration.rb', 'db/migrate/my_feeds_migration.rb'
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.next_migration_number(dirname)
|
16
|
-
if ActiveRecord::Base.timestamped_migrations
|
17
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
18
|
-
else
|
19
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_model
|
24
|
-
template "model.rb", File.join('app/models', "feed.rb")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|