shiroyagi 1.2.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 209a38be8805b5d4d3f104a3ba9496d0eec4adfc199988158ead4a76bbf0fbbe
4
- data.tar.gz: bf7a4b3b5a7608795d819d77a34d1d0e399efd49fa04d513a56e914dac7fa20d
3
+ metadata.gz: ea26658917cd80c6b73a88485ea673c1fc7bb134057e80b829128b5f9e0e3d78
4
+ data.tar.gz: 578caadf70d4954dfe512e3ec3c813d5374d2badb5feadfb53d3df0a5cb410df
5
5
  SHA512:
6
- metadata.gz: e9b1ad10dd39a629c8fdaaa6272fd4bba38ba1e610c93bc65c72a835527373af419ab3956b2e98608c852161f8f84877c0362b4ac8a2494d46a3c1d8d3b9ab99
7
- data.tar.gz: 5c85132b40387266b68b0fef0916e63a365a491c322dc19670b8405fdf53628da824f8426c132270e94f13126dd5c91dfedb57a111afdfc80a89f5a796f629f2
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(read_at: Time.current)
23
+ unreads.update(read_management_column_name => Time.current)
20
24
  end
21
25
 
22
26
  def mark_all_as_unread
23
- reads.update(read_at: nil)
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(read_at: nil) }
29
- scope :unreads, -> { where(read_at: nil) }
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(read_at: Time.current) if unread?
36
+ update(read_management_column_name => Time.current) if unread?
33
37
  end
34
38
 
35
39
  def mark_as_unread
36
- update(read_at: nil) if read?
40
+ update(read_management_column_name => nil) if read?
37
41
  end
38
42
 
39
43
  def mark_as_read!
40
- update!(read_at: Time.current) if unread?
44
+ update!(read_management_column_name => Time.current) if unread?
41
45
  end
42
46
 
43
47
  def mark_as_unread!
44
- update!(read_at: nil) if read?
48
+ update!(read_management_column_name => nil) if read?
45
49
  end
46
50
 
47
51
  def read?
48
- read_at.present?
52
+ send(read_management_column_name).present?
49
53
  end
50
54
 
51
55
  def unread?
52
- read_at.blank?
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
@@ -1,3 +1,3 @@
1
1
  module Shiroyagi
2
- VERSION = '1.2.0'
2
+ VERSION = '1.4.0'
3
3
  end
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.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rui Onodera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 4.0.2
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: '0'
54
+ version: 4.0.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: factory_bot_rails
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.3
116
+ rubygems_version: 3.2.33
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Read/Unread status management module for Rails.