acts_as_reactable 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +63 -4
- data/lib/acts_as_reactable/reaction.rb +0 -2
- data/lib/acts_as_reactable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0d2ddf2e316f3491c4fbf11f4bdc6d02186135f1377cfcb13e0f704ebbcd26
|
4
|
+
data.tar.gz: f251f43db52dc488e4c0ed8270e8b16c5c32e2f613633bf625e67cb2f76945c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4589911e039c80372bdc9ea82fc4be81a2505814781aa2a7da7030579d0a573463b91e70c996ea509bd53e183a60bf2c085088a67a7d738177e2c8a96ee58a9d
|
7
|
+
data.tar.gz: 8c7a482a922045884b89ff174d3f7012486cb815f86638dfed001270565f7edd1496dbd3cec7e9f79c5ded88b50fbc1e31155df5a0fa69ce7716f47b303d6183
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
### [0.2.8](https://github.com/public-reactions/acts_as_reactable/compare/v0.2.7...v0.2.8) (2022-04-18)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* remove needless validators ([2b6aef3](https://github.com/public-reactions/acts_as_reactable/commit/2b6aef3379da7d3aa9a969440720b04d005a78af))
|
9
|
+
* **spec:** test spec for #destroy_reaction_from ([ef79759](https://github.com/public-reactions/acts_as_reactable/commit/ef79759ce20109299e8bffa78ad4b7f0784510e0))
|
10
|
+
|
3
11
|
### [0.2.7](https://github.com/public-reactions/acts_as_reactable/compare/v0.2.6...v0.2.7) (2022-04-14)
|
4
12
|
|
5
13
|
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
![build](https://github.com/public-reactions/acts_as_reactable/actions/workflows/main.yml/badge.svg)
|
4
4
|
[![codecov](https://codecov.io/gh/public-reactions/acts_as_reactable/branch/main/graph/badge.svg?token=OVDCJIQAFN)](https://codecov.io/gh/public-reactions/acts_as_reactable)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/acts_as_reactable.svg)](https://badge.fury.io/rb/acts_as_reactable)
|
6
|
+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -18,21 +19,79 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
19
|
|
19
20
|
### 1. create the Reaction model
|
20
21
|
|
22
|
+
```ruby
|
23
|
+
# with default bigint id
|
24
|
+
create_table :reactions do |t|
|
25
|
+
t.references :reactable, polymorphic: true, null: false
|
26
|
+
t.references :reactor, polymorphic: true, null: false
|
27
|
+
|
28
|
+
t.string :emoji, null: false, index: true
|
29
|
+
|
30
|
+
t.timestamps
|
31
|
+
end
|
32
|
+
|
33
|
+
# with uuid id
|
34
|
+
create_table :reactions do |t|
|
35
|
+
t.references :reactable, polymorphic: true, type: :uuid, null: false
|
36
|
+
t.references :reactor, polymorphic: true, type: :uuid, null: false
|
37
|
+
|
38
|
+
t.string :emoji, null: false, index: true
|
39
|
+
|
40
|
+
t.timestamps
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
21
44
|
### 2. annotate reactable and reactor models
|
22
45
|
|
46
|
+
```ruby
|
47
|
+
# reactable
|
48
|
+
class Post < ApplicationRecord
|
49
|
+
acts_as_reactable
|
50
|
+
end
|
51
|
+
|
52
|
+
# reactor
|
53
|
+
class User < ApplicationRecord
|
54
|
+
acts_as_reactor
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
23
58
|
### 3. creating/updating reactions
|
24
59
|
|
60
|
+
```ruby
|
61
|
+
reaction = post.update_reaction_from(user, "😀")
|
62
|
+
```
|
63
|
+
|
25
64
|
### 4. deleting reactions
|
26
65
|
|
27
|
-
|
66
|
+
```ruby
|
67
|
+
post.destroy_reaction_from(user) # returns value like #destroy in ActiveRecord
|
68
|
+
|
69
|
+
# #update_reaction_from with a nil reaction also delete the reaction
|
70
|
+
post.update_reaction_from(user)
|
71
|
+
```
|
72
|
+
|
73
|
+
### 5. private opinion from one reactor
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
reaction = ActsAsReactable::Reaction.find_by(reactable: self, reactor: user)&.emoji
|
77
|
+
```
|
78
|
+
|
79
|
+
### 6. group, count and sort to get a summary of public opinion
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
ActsAsReactable::Reaction.where(reactable: reactor).group(:emoji).order('count_id DESC').count(:id)
|
83
|
+
|
84
|
+
# { "😀": 10, "😢": 5, "😣": 1 }
|
85
|
+
```
|
28
86
|
|
29
87
|
## FAQ
|
30
88
|
|
31
89
|
### Why saving the emoji character instead of "smily_face"
|
32
90
|
|
33
|
-
- Technically, there's no concrete name/key/id for emoji (and modifiers like skin tone). The [CLDR short names](https://unicode.org/emoji/format.html#col-name) "vary by language" and "may change".
|
34
|
-
- It's easier to store since
|
35
|
-
- It's
|
91
|
+
- Technically, there's no concrete name/key/id for emoji (and modifiers like skin tone). The [CLDR short names](https://unicode.org/emoji/format.html#col-name) "vary by language" and "may change", besides, are those names case sensitive? Should we use `-`, `_` or ` ` as divider? How to append tone variant? There are several error prone decisions to make.
|
92
|
+
- It's easier to store since all modern database supports encodings (e.g. UTF-8) for unicode characters.
|
93
|
+
- It's easy to validate with libs/regex (e.g. [unicode-emoji](https://github.com/janlelis/unicode-emoji)).
|
94
|
+
- It takes less size on disk to store (and presumably less time to index/sort/match) one unicode character 😂 (4 bytes) than `face with tears of joy` (22 bytes). [This is a great article to explain how utf-8 works](https://sethmlarson.dev/blog/utf-8)
|
36
95
|
|
37
96
|
## Development
|
38
97
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_reactable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- contact@public-reactions.com
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|