acts_as_reactable 0.1.0 → 0.3.0

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: 3f98c270221c9290d14ccbf602d3c23d613081c140adb9d295868681cf87c8de
4
- data.tar.gz: 51248db8027acf4a10dd8971365ba1eb8be09f7006a94b0d55148bd5f31c468e
3
+ metadata.gz: ef084116ccbe7e59160dfda29dd6fd2679a2f1d425c689b4ac4fbb764e309ff4
4
+ data.tar.gz: 4612e402698fee627577269f661ba646c33c5624d92a8a228c4d9c1f453b7483
5
5
  SHA512:
6
- metadata.gz: 5d9f2925ed9204542f32b6e87548f78972106b4c2b7c9f31bdc1de44e156cda1cf85a1f162c12f3a5b9629190c2deae2d2a5851f80b2c5531377ba77b8b1ecdb
7
- data.tar.gz: 1fbdecece42f4122db297712d6de6a0801bd8afade10b957f13047cc5d12af02a3c8d57dc2099d4e1b176f5ea1b1c3cd277806f3234f30bba2917822ad916fea
6
+ metadata.gz: e85624536581e31d3844f2b4ebc3a6d30443a998924bf3abf6999035e4f7cc1439de643e066ba161c34beb7e8c2bb62d156542a7f84686cfad1e54c906b57ba2
7
+ data.tar.gz: a1c03a4130d202328df9d83132c917dff7a467d71b07822efd4f62b88f690932b546b86022b5d6c433e0ee8bce3d48e3d30d036a8501498f57b375e6688a5a44
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0](https://github.com/public-reactions/acts_as_reactable/compare/v0.2.8...v0.3.0) (2022-04-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * enable multiple reactions to single subject for each user ([ec32854](https://github.com/public-reactions/acts_as_reactable/commit/ec32854897249a53d2a17b41509d7c7ab69bb680))
9
+
10
+ ### [0.2.8](https://github.com/public-reactions/acts_as_reactable/compare/v0.2.7...v0.2.8) (2022-04-18)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * remove needless validators ([2b6aef3](https://github.com/public-reactions/acts_as_reactable/commit/2b6aef3379da7d3aa9a969440720b04d005a78af))
16
+ * **spec:** test spec for #destroy_reaction_from ([ef79759](https://github.com/public-reactions/acts_as_reactable/commit/ef79759ce20109299e8bffa78ad4b7f0784510e0))
17
+
18
+ ### [0.2.7](https://github.com/public-reactions/acts_as_reactable/compare/v0.2.6...v0.2.7) (2022-04-14)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * reset version to 0.2.0 ([fcb818a](https://github.com/public-reactions/acts_as_reactable/commit/fcb818a535e2435f03c9bd9894e5f6016e5b9899))
24
+
25
+ ## [0.2.0](https://github.com/public-reactions/acts_as_reactable/compare/v0.1.0...v0.2.0) (2022-04-14)
26
+
27
+
28
+ ### ⚠ BREAKING CHANGES
29
+
30
+ * #upgrade_reaction_from now returns the created reaction
31
+
32
+ ### Features
33
+
34
+ * #upgrade_reaction_from now returns the created reaction ([31bacd8](https://github.com/public-reactions/acts_as_reactable/commit/31bacd8598bc250e3bc9b2c5352d155058091f42))
35
+
3
36
  ## [0.1.0] - 2022-04-06
4
37
 
5
38
  - Initial release
data/README.md CHANGED
@@ -2,9 +2,8 @@
2
2
 
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
-
6
- TODO: Add badge for gem
7
- TODO: Add badge for coverage
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)
8
7
 
9
8
  ## Installation
10
9
 
@@ -20,21 +19,79 @@ If bundler is not being used to manage dependencies, install the gem by executin
20
19
 
21
20
  ### 1. create the Reaction model
22
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
+
23
44
  ### 2. annotate reactable and reactor models
24
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
+
25
58
  ### 3. creating/updating reactions
26
59
 
60
+ ```ruby
61
+ reaction = post.update_reaction_from(user, "😀")
62
+ ```
63
+
27
64
  ### 4. deleting reactions
28
65
 
29
- ### 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
+ ```
30
86
 
31
87
  ## FAQ
32
88
 
33
- ### Why saving the emoji character instead of "smily_face"
89
+ ### Why saving "😂" instead of "face_with_tears_of_joy"
34
90
 
35
- - 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".
36
- - It's easier to store since any modern database supports
37
- - 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)
38
95
 
39
96
  ## Development
40
97
 
@@ -44,7 +101,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
101
 
45
102
  ## Contributing
46
103
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/acts_as_reactable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/acts_as_reactable/blob/main/CODE_OF_CONDUCT.md).
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/public-reactions/acts_as_reactable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/acts_as_reactable/blob/main/CODE_OF_CONDUCT.md).
48
105
 
49
106
  ## License
50
107
 
@@ -25,9 +25,8 @@ module ActsAsReactable
25
25
  return destroy_reaction_from(reactor)
26
26
  end
27
27
 
28
- reaction = reactions.find_or_initialize_by(reactor: reactor)
29
- reaction.emoji = emoji
30
- reaction.save
28
+ reaction = reactions.where({reactor: reactor, emoji: emoji}).first_or_create
29
+ reaction
31
30
  end
32
31
  end
33
32
  end
@@ -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.1.0"
4
+ VERSION = "0.3.0"
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - admin@public-reactions.com
8
- autorequire:
7
+ - contact@public-reactions.com
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-09 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.11'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.11'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: standard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '13.0'
61
+ version: '1.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '13.0'
68
+ version: '1.10'
69
69
  - !ruby/object:Gem::Dependency
70
- name: standard
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.3'
75
+ version: '3.11'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.3'
82
+ version: '3.11'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -152,21 +152,18 @@ dependencies:
152
152
  version: '0'
153
153
  description: Emoji reactions for rails
154
154
  email:
155
- - admin@public-reactions.com
155
+ - contact@public-reactions.com
156
156
  executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".rspec"
161
- - ".standard.yml"
162
161
  - CHANGELOG.md
163
162
  - CODE_OF_CONDUCT.md
164
163
  - Gemfile
165
- - Gemfile.lock
166
164
  - LICENSE.txt
167
165
  - README.md
168
166
  - Rakefile
169
- - acts_as_reactable.gemspec
170
167
  - lib/acts_as_reactable.rb
171
168
  - lib/acts_as_reactable/reactable.rb
172
169
  - lib/acts_as_reactable/reaction.rb
@@ -180,7 +177,7 @@ metadata:
180
177
  homepage_uri: https://github.com/public-reactions/acts_as_reactable
181
178
  source_code_uri: https://github.com/public-reactions/acts_as_reactable
182
179
  changelog_uri: https://github.com/public-reactions/acts_as_reactable
183
- post_install_message:
180
+ post_install_message:
184
181
  rdoc_options: []
185
182
  require_paths:
186
183
  - lib
@@ -196,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
193
  version: '0'
197
194
  requirements: []
198
195
  rubygems_version: 3.3.7
199
- signing_key:
196
+ signing_key:
200
197
  specification_version: 4
201
198
  summary: Emoji reactions for rails
202
199
  test_files: []
data/.standard.yml DELETED
@@ -1,3 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/testdouble/standard
3
- ruby_version: 2.6
data/Gemfile.lock DELETED
@@ -1,151 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- acts_as_reactable (0.1.0)
5
- activerecord (>= 6.0)
6
- unicode-emoji (~> 3.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (7.0.2.2)
12
- actionview (= 7.0.2.2)
13
- activesupport (= 7.0.2.2)
14
- rack (~> 2.0, >= 2.2.0)
15
- rack-test (>= 0.6.3)
16
- rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (7.0.2.2)
19
- activesupport (= 7.0.2.2)
20
- builder (~> 3.1)
21
- erubi (~> 1.4)
22
- rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activemodel (7.0.2.2)
25
- activesupport (= 7.0.2.2)
26
- activerecord (7.0.2.2)
27
- activemodel (= 7.0.2.2)
28
- activesupport (= 7.0.2.2)
29
- activesupport (7.0.2.2)
30
- concurrent-ruby (~> 1.0, >= 1.0.2)
31
- i18n (>= 1.6, < 2)
32
- minitest (>= 5.1)
33
- tzinfo (~> 2.0)
34
- ast (2.4.2)
35
- builder (3.2.4)
36
- concurrent-ruby (1.1.10)
37
- crass (1.0.6)
38
- diff-lcs (1.5.0)
39
- docile (1.4.0)
40
- erubi (1.10.0)
41
- factory_bot (6.2.1)
42
- activesupport (>= 5.0.0)
43
- i18n (1.10.0)
44
- concurrent-ruby (~> 1.0)
45
- loofah (2.14.0)
46
- crass (~> 1.0.2)
47
- nokogiri (>= 1.5.9)
48
- method_source (1.0.0)
49
- minitest (5.15.0)
50
- nokogiri (1.13.3-x86_64-darwin)
51
- racc (~> 1.4)
52
- nokogiri (1.13.3-x86_64-linux)
53
- racc (~> 1.4)
54
- parallel (1.22.1)
55
- parser (3.1.1.0)
56
- ast (~> 2.4.1)
57
- racc (1.6.0)
58
- rack (2.2.3)
59
- rack-test (1.1.0)
60
- rack (>= 1.0, < 3)
61
- rails-dom-testing (2.0.3)
62
- activesupport (>= 4.2.0)
63
- nokogiri (>= 1.6)
64
- rails-html-sanitizer (1.4.2)
65
- loofah (~> 2.3)
66
- railties (7.0.2.2)
67
- actionpack (= 7.0.2.2)
68
- activesupport (= 7.0.2.2)
69
- method_source
70
- rake (>= 12.2)
71
- thor (~> 1.0)
72
- zeitwerk (~> 2.5)
73
- rainbow (3.1.1)
74
- rake (13.0.6)
75
- regexp_parser (2.2.1)
76
- rexml (3.2.5)
77
- rspec (3.11.0)
78
- rspec-core (~> 3.11.0)
79
- rspec-expectations (~> 3.11.0)
80
- rspec-mocks (~> 3.11.0)
81
- rspec-core (3.11.0)
82
- rspec-support (~> 3.11.0)
83
- rspec-expectations (3.11.0)
84
- diff-lcs (>= 1.2.0, < 2.0)
85
- rspec-support (~> 3.11.0)
86
- rspec-mocks (3.11.1)
87
- diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.11.0)
89
- rspec-rails (5.1.0)
90
- actionpack (>= 5.2)
91
- activesupport (>= 5.2)
92
- railties (>= 5.2)
93
- rspec-core (~> 3.10)
94
- rspec-expectations (~> 3.10)
95
- rspec-mocks (~> 3.10)
96
- rspec-support (~> 3.10)
97
- rspec-support (3.11.0)
98
- rubocop (1.26.1)
99
- parallel (~> 1.10)
100
- parser (>= 3.1.0.0)
101
- rainbow (>= 2.2.2, < 4.0)
102
- regexp_parser (>= 1.8, < 3.0)
103
- rexml
104
- rubocop-ast (>= 1.16.0, < 2.0)
105
- ruby-progressbar (~> 1.7)
106
- unicode-display_width (>= 1.4.0, < 3.0)
107
- rubocop-ast (1.16.0)
108
- parser (>= 3.1.1.0)
109
- rubocop-performance (1.13.3)
110
- rubocop (>= 1.7.0, < 2.0)
111
- rubocop-ast (>= 0.4.0)
112
- ruby-progressbar (1.11.0)
113
- simplecov (0.21.2)
114
- docile (~> 1.1)
115
- simplecov-html (~> 0.11)
116
- simplecov_json_formatter (~> 0.1)
117
- simplecov-cobertura (2.1.0)
118
- rexml
119
- simplecov (~> 0.19)
120
- simplecov-html (0.12.3)
121
- simplecov_json_formatter (0.1.4)
122
- sqlite3 (1.4.2)
123
- standard (1.9.1)
124
- rubocop (= 1.26.1)
125
- rubocop-performance (= 1.13.3)
126
- thor (1.2.1)
127
- tzinfo (2.0.4)
128
- concurrent-ruby (~> 1.0)
129
- unicode-display_width (2.1.0)
130
- unicode-emoji (3.1.0)
131
- unicode-version (~> 1.0)
132
- unicode-version (1.2.0)
133
- zeitwerk (2.5.4)
134
-
135
- PLATFORMS
136
- x86_64-darwin-21
137
- x86_64-linux
138
-
139
- DEPENDENCIES
140
- acts_as_reactable!
141
- factory_bot (~> 6.0)
142
- rake (~> 13.0)
143
- rspec (~> 3.11)
144
- rspec-rails (~> 5.0)
145
- simplecov
146
- simplecov-cobertura
147
- sqlite3
148
- standard (~> 1.3)
149
-
150
- BUNDLED WITH
151
- 2.3.10
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/acts_as_reactable/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "acts_as_reactable"
7
- spec.version = ActsAsReactable::VERSION
8
- spec.authors = ["admin@public-reactions.com"]
9
- spec.email = ["admin@public-reactions.com"]
10
-
11
- spec.summary = "Emoji reactions for rails"
12
- spec.description = "Emoji reactions for rails"
13
- spec.homepage = "https://github.com/public-reactions/acts_as_reactable"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/public-reactions/acts_as_reactable"
21
- spec.metadata["changelog_uri"] = "https://github.com/public-reactions/acts_as_reactable"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.add_runtime_dependency "activerecord", [">= 6.0"]
35
- spec.add_runtime_dependency "unicode-emoji", "~> 3.1"
36
-
37
- spec.add_development_dependency "rspec", "~> 3.11"
38
- spec.add_development_dependency "rake", "~> 13.0"
39
- spec.add_development_dependency "standard", "~> 1.3"
40
- spec.add_development_dependency "rspec-rails", "~> 5.0"
41
- spec.add_development_dependency "factory_bot", "~> 6.0"
42
- spec.add_development_dependency "sqlite3"
43
- spec.add_development_dependency "simplecov"
44
- spec.add_development_dependency "simplecov-cobertura"
45
-
46
- # For more information and examples about making a new gem, check out our
47
- # guide at: https://bundler.io/guides/creating_gem.html
48
- end