shiroyagi 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/shiroyagi/acts_as_shiroyagi.rb +21 -11
- data/lib/shiroyagi/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea26658917cd80c6b73a88485ea673c1fc7bb134057e80b829128b5f9e0e3d78
|
4
|
+
data.tar.gz: 578caadf70d4954dfe512e3ec3c813d5374d2badb5feadfb53d3df0a5cb410df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f5eef44ffbaaa83d5b48be6c8a5b11f8d446b86aedbaf9e6e683fe7cf8f7d40c8e4940d9e662b01609205f72d26f16a8cdb53750866cfe42dd5b4775e75e0cd
|
7
|
+
data.tar.gz: '091d520a09d03fb0208a24a6d61c93ae83be4b21f340877baf8c28bdf3ef3869a79576e1969282f20de19154b3b9a6c8caad31fd9b40c1c63f4ef242f7816250'
|
data/README.md
CHANGED
@@ -18,6 +18,16 @@ class Message < ApplicationRecord
|
|
18
18
|
end
|
19
19
|
```
|
20
20
|
|
21
|
+
If you want to use a different column, you can specify it with `acts_as_shiroyagi`
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Message < ApplicationRecord
|
25
|
+
include Shiroyagi::ActsAsShiroyagi
|
26
|
+
|
27
|
+
acts_as_shiroyagi column: 'user_read_at'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
21
31
|
That's it! Then you can use the following methods.
|
22
32
|
|
23
33
|
```ruby
|
@@ -3,8 +3,12 @@ module Shiroyagi
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
class_methods do
|
6
|
-
# TODO: The read_at column name should be customizable via an argument.
|
7
6
|
def acts_as_shiroyagi(options = {})
|
7
|
+
@read_management_column_name = options[:column].to_sym if options[:column].present?
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_management_column_name
|
11
|
+
@read_management_column_name || :read_at
|
8
12
|
end
|
9
13
|
|
10
14
|
def reads_count
|
@@ -16,41 +20,47 @@ module Shiroyagi
|
|
16
20
|
end
|
17
21
|
|
18
22
|
def mark_all_as_read
|
19
|
-
unreads.update(
|
23
|
+
unreads.update(read_management_column_name => Time.current)
|
20
24
|
end
|
21
25
|
|
22
26
|
def mark_all_as_unread
|
23
|
-
reads.update(
|
27
|
+
reads.update(read_management_column_name => nil)
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
31
|
included do
|
28
|
-
scope :reads, -> { where.not(
|
29
|
-
scope :unreads, -> { where(
|
32
|
+
scope :reads, -> { where.not(read_management_column_name => nil) }
|
33
|
+
scope :unreads, -> { where(read_management_column_name => nil) }
|
30
34
|
|
31
35
|
def mark_as_read
|
32
|
-
update(
|
36
|
+
update(read_management_column_name => Time.current) if unread?
|
33
37
|
end
|
34
38
|
|
35
39
|
def mark_as_unread
|
36
|
-
update(
|
40
|
+
update(read_management_column_name => nil) if read?
|
37
41
|
end
|
38
42
|
|
39
43
|
def mark_as_read!
|
40
|
-
update!(
|
44
|
+
update!(read_management_column_name => Time.current) if unread?
|
41
45
|
end
|
42
46
|
|
43
47
|
def mark_as_unread!
|
44
|
-
update!(
|
48
|
+
update!(read_management_column_name => nil) if read?
|
45
49
|
end
|
46
50
|
|
47
51
|
def read?
|
48
|
-
|
52
|
+
send(read_management_column_name).present?
|
49
53
|
end
|
50
54
|
|
51
55
|
def unread?
|
52
|
-
|
56
|
+
send(read_management_column_name).blank?
|
53
57
|
end
|
54
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def read_management_column_name
|
63
|
+
self.class.read_management_column_name
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/shiroyagi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiroyagi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rui Onodera
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -98,7 +98,7 @@ homepage: https://github.com/Findy/shiroyagi
|
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|
101
|
-
post_install_message:
|
101
|
+
post_install_message:
|
102
102
|
rdoc_options: []
|
103
103
|
require_paths:
|
104
104
|
- lib
|
@@ -113,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.33
|
117
|
+
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: Read/Unread status management module for Rails.
|
120
120
|
test_files: []
|