acts_as_able 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9b0001a19a3557390ad09e790f82aeeea82bb236ef0204bf06682454d9dda03
4
- data.tar.gz: c70052968040c5f9a8fab587ab7f92c5af1333819b1ac9d43810752dfd3e9b26
3
+ metadata.gz: cc3452bc17d901c282e9aa982f85c5ae80e29a8240cba9bb6a0dea3c2080acfc
4
+ data.tar.gz: ee0890f0f5cba53be74ec4909d881c2ef239eb285363b025d564632392ac96c2
5
5
  SHA512:
6
- metadata.gz: f304b0bd272210243d6ff822d6295dbecdf9c8bc2e0dd2dbdf496184c381805d2c3e9abe761ae2d90b3a167c89eb605372595cb77b3f544535d7100ab2cdb9f9
7
- data.tar.gz: a0ef45ec93a5d48e9f8c6b94d19661c14501c2d994c5219b8e4cb852e1965852473b7f8abc72de429387b60123055835ea20a05b66b0df68c8a7c8ab62438152
6
+ metadata.gz: ded131016598b2685f0c10e5d80d05c47d08d565ca740b7e442703d7d0edf171c7200ef9f8ca37b1d1c49416a053512d84bf85ce7d43fb0f4d837b5e82b7bab9
7
+ data.tar.gz: 8d01095e82b2787e6423b8564af9e34884e1ff864da812b7b7060f4263e9d4232c8552dddae8248fbfe6fb167a0e363f415eb1ee31d12480447ec8b1a37000c0
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <!--
2
2
  * @Date: 2021-05-14 15:55:52
3
3
  * @LastEditors: viletyy
4
- * @LastEditTime: 2021-05-14 16:37:30
5
- * @FilePath: /acts_as_followable/README.md
4
+ * @LastEditTime: 2021-06-02 18:51:43
5
+ * @FilePath: /acts_as_able/README.md
6
6
  -->
7
- # ActsAsFollowable
7
+ # ActsAsAble
8
8
 
9
9
  这就是一个给国人用的 关注、浏览、点赞等有关的 Gem
10
10
 
@@ -13,7 +13,7 @@
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'acts_as_able', git: 'git://github.com/viletyy/acts_as_able.git'
16
+ gem 'acts_as_able'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -48,7 +48,7 @@ acts_as_followable
48
48
  acts_as_followable
49
49
 
50
50
  #找出某个模型关注我的所有的对象
51
- Article.followers_by_type(User)
51
+ Article.last.followers_by_type(User)
52
52
  ```
53
53
 
54
54
  acts_as_follower
@@ -64,7 +64,188 @@ User.first.follow?(Article.first)
64
64
  # 查看关注模型的所有对象
65
65
  User.first.followings(Article)
66
66
  ```
67
- 以上是目前实现的功能 还有黑名单等功能待实现
67
+
68
+ ### 浏览功能
69
+ ```ruby
70
+ rails g acts_as_viewable
71
+ rails db:migrate
72
+ ```
73
+
74
+ 以下方法可以放在需要使用的类中:
75
+ ```ruby
76
+ acts_as_viewable #被浏览
77
+ acts_as_viewer #浏览者
78
+
79
+
80
+ class Article < ApplicationRecord
81
+ acts_as_viewable
82
+ end
83
+
84
+ class User < ApplicationRecord
85
+ acts_as_viewer
86
+ end
87
+ ```
88
+
89
+ acts_as_viewable
90
+ ```ruby
91
+ acts_as_viewable
92
+
93
+ #找出某个模型浏览我的所有的对象
94
+ Article.last.viewers_by_type(User)
95
+ ```
96
+
97
+ acts_as_viewer
98
+ ```ruby
99
+ acts_as_viewer
100
+
101
+ # 浏览某个模型的某个对象
102
+ User.first.view(Article.first)
103
+ # 查看是否浏览某个对象
104
+ User.first.view?(Article.first)
105
+ # 查看某种类型浏览的所有对象
106
+ User.first.viewings(Article)
107
+ ```
108
+
109
+ ### 点赞功能
110
+ ```ruby
111
+ rails g acts_as_likable
112
+ rails db:migrate
113
+ ```
114
+
115
+ 以下方法可以放在需要使用的类中:
116
+ ```ruby
117
+ acts_as_likable #被点赞
118
+ acts_as_liker #点赞者
119
+
120
+
121
+ class Article < ApplicationRecord
122
+ acts_as_likable
123
+ end
124
+
125
+ class User < ApplicationRecord
126
+ acts_as_liker
127
+ end
128
+ ```
129
+
130
+ acts_as_likable
131
+ ```ruby
132
+ acts_as_likable
133
+
134
+ #找出某个模型点赞我的所有的对象
135
+ Article.last.likers_by_type(User)
136
+ ```
137
+
138
+ acts_as_liker
139
+ ```ruby
140
+ acts_as_liker
141
+
142
+ # 点赞某个模型的某个对象
143
+ User.first.like(Article.first)
144
+ # 取消某个对象的点赞
145
+ User.first.unlike(Article.first)
146
+ # 查看是否点赞某个对象
147
+ User.first.like?(Article.first)
148
+ # 查看点赞模型的所有对象
149
+ User.first.likings(Article)
150
+ ```
151
+
152
+ ### 踩功能
153
+ ```ruby
154
+ rails g acts_as_dissable
155
+ rails db:migrate
156
+ ```
157
+
158
+ 以下方法可以放在需要使用的类中:
159
+ ```ruby
160
+ acts_as_dissable #被踩
161
+ acts_as_disser #踩者
162
+
163
+
164
+ class Article < ApplicationRecord
165
+ acts_as_dissable
166
+ end
167
+
168
+ class User < ApplicationRecord
169
+ acts_as_disser
170
+ end
171
+ ```
172
+
173
+ acts_as_dissable
174
+ ```ruby
175
+ acts_as_dissable
176
+
177
+ #找出某个模型点赞我的所有的对象
178
+ Article.last.dissers_by_type(User)
179
+ ```
180
+
181
+ acts_as_disser
182
+ ```ruby
183
+ acts_as_disser
184
+
185
+ # 踩某个模型的某个对象
186
+ User.first.diss(Article.first)
187
+ # 取消某个对象的踩
188
+ User.first.undiss(Article.first)
189
+ # 查看是否踩了某个对象
190
+ User.first.diss?(Article.first)
191
+ # 查看踩模型的所有对象
192
+ User.first.dissings(Article)
193
+ ```
194
+
195
+ ### 评论功能
196
+ ```ruby
197
+ rails g acts_as_commentable
198
+ rails db:migrate
199
+ ```
200
+
201
+ 以下方法可以放在需要使用的类中:
202
+ ```ruby
203
+ acts_as_commentable #被点赞
204
+ acts_as_commenter #点赞者
205
+
206
+
207
+ class Article < ApplicationRecord
208
+ acts_as_commentable
209
+ end
210
+
211
+ class User < ApplicationRecord
212
+ acts_as_commenter
213
+ end
214
+ ```
215
+
216
+ acts_as_commentable
217
+ ```ruby
218
+ acts_as_commentable
219
+
220
+ #我的所有一级评论
221
+ Article.last.root_commenters
222
+ #某个模型的一级评论
223
+ Article.last.root_commenters_by_type(User)
224
+ #找出某个模型评论我的所有的对象
225
+ Article.last.commenters_by_type(User)
226
+ ```
227
+
228
+ acts_as_commenter
229
+ ```ruby
230
+ acts_as_commenter
231
+
232
+ # 评论某个模型的某个对象
233
+ User.first.comment('评论内容', Article.first, nil)
234
+ # 查看是否评论某个对象或回复某个对象
235
+ User.first.comment?(Article.first)
236
+ # 查看某种类型评论的所有对象
237
+ User.first.committings(Article)
238
+
239
+ ```
240
+
241
+ comment
242
+ ```ruby
243
+ # 查看父级评论
244
+ Comment.first.parent_comment
245
+ # 查看子评论
246
+ Comment.first.children_comments
247
+ ```
248
+
68
249
  ## License
69
250
 
70
251
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -18,13 +18,23 @@ module ActsAsAble
18
18
  def root_commenters
19
19
  self.commenters.where(parent_id: nil)
20
20
  end
21
+
22
+ def root_commenters_by_type(commenter_type, options= {})
23
+ ids = Comment.
24
+ where('commentable_id' => self.id,
25
+ 'commentable_type' => class_name(self),
26
+ 'commenter_type' => commenter_type.name,
27
+ 'parent_id' => nil
28
+ ).pluck('commenter_id')
29
+ return commenter_type.where("id in (?)", ids)
30
+ end
21
31
 
22
32
  def comment_count
23
33
  self.commenters.count
24
34
  end
25
35
 
26
36
  def commenters_by_type(commenter_type, options = {})
27
- ids = Diss.
37
+ ids = Comment.
28
38
  where('commentable_id' => self.id,
29
39
  'commentable_type' => class_name(self),
30
40
  'commenter_type' => commenter_type.name
@@ -15,11 +15,6 @@ module ActsAsAble
15
15
  end
16
16
 
17
17
  module InstanceMethods
18
- # 所有的一级评论
19
- def root_comments
20
- self.comments.where(parent_id: nil)
21
- end
22
-
23
18
  # 评论某对象
24
19
  def comment(content, obj, parent_comment = nil)
25
20
  if parent_comment.present? && parent_comment.is_a?(Comment)
@@ -1,3 +1,3 @@
1
1
  module ActsAsAble
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_able
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viletyy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-17 00:00:00.000000000 Z
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler