acts_as_reactable 0.2.7 → 0.2.8

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: 8bfe9ba5656866d662b502fc6c04288c05e8b2ecde0a48a4812f5dc5c12607da
4
- data.tar.gz: 1f16f5de5bb6fd29c7e9f2afee9b22d8d692d88d8a3103e208e4764124a30118
3
+ metadata.gz: cc0d2ddf2e316f3491c4fbf11f4bdc6d02186135f1377cfcb13e0f704ebbcd26
4
+ data.tar.gz: f251f43db52dc488e4c0ed8270e8b16c5c32e2f613633bf625e67cb2f76945c3
5
5
  SHA512:
6
- metadata.gz: 372e7d0ab30345f4b5870338d4c7b8006041d50b84e25c93d853b0dd8ed961724fac9fb2b7005dbc2b0ad3de7c80469812bc16e14ac3520fdb3e4933bf14be58
7
- data.tar.gz: 168c5407c7934db6b4ddd4a3b3d86684af2362e1a6818e90bcdbdfcac84aa68c6163d212e3c43fb84b99597fbb3579541f4956b191a6f39010cb5f623cab234a
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
- ### 5. aggregate/summary of reactions
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 any modern database supports
35
- - It's easier to validate with libs/regex (e.g. [unicode-emoji](https://github.com/janlelis/unicode-emoji))
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
 
@@ -5,8 +5,6 @@ module ActsAsReactable
5
5
  belongs_to :reactable, polymorphic: true
6
6
  belongs_to :reactor, polymorphic: true
7
7
 
8
- validates_presence_of :reactable_id
9
- validates_presence_of :reactor_id
10
8
  validates_format_of :emoji, with: Unicode::Emoji::REGEX
11
9
  end
12
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsReactable
4
- VERSION = "0.2.7"
4
+ VERSION = "0.2.8"
5
5
  end
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.7
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-14 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord