shiroyagi 1.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +88 -0
- data/Rakefile +23 -0
- data/lib/shiroyagi.rb +4 -0
- data/lib/shiroyagi/acts_as_shiroyagi.rb +56 -0
- data/lib/shiroyagi/version.rb +3 -0
- data/lib/tasks/shiroyagi_tasks.rake +4 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f3af95d866483aebdc0add25d148f9b07b4d3df
|
4
|
+
data.tar.gz: ac166dbf8ec135c78b67df3342429f2cfcd9b9aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a19db89f032a7fa33ebf74df353dfb4fef5ea57da58f5ac06ba49581210142d462800fe8e10af4330008ea3d762f2f02956d80208a49e8f565f8e39287b198b0
|
7
|
+
data.tar.gz: 3ebcd1594defac9c4239d5b3ca09433fb959e4454bc90a9130a66eca702ebcbd7cc1ce7a62edab0f370939251509a95a4d40b6d8b500fe878031183bc2fe8973
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Rui Onodera
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Shiroyagi
|
2
|
+
|
3
|
+
Shiroyagi is a thin Rails plugin which manages Read/Unread status of a Model.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add a column name `read_at` to your model. This column is used by status management.
|
8
|
+
|
9
|
+
```
|
10
|
+
bin/rails g migration AddColumnToYourModels read_at:datetime
|
11
|
+
```
|
12
|
+
|
13
|
+
Include the `Shiroyagi::ActsAsShiroyagi` module in your class.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class Message < ApplicationRecord
|
17
|
+
include Shiroyagi::ActsAsShiroyagi
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
That's it! Then you can use the following methods.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# Class methods
|
25
|
+
|
26
|
+
Message.reads
|
27
|
+
=> [#<Message id: 1, read_at: Tue, 28 Nov 2017 07:59:47 UTC +00:00>]
|
28
|
+
|
29
|
+
Message.unreads
|
30
|
+
=> [#<Message id: 2, read_at: nil>]
|
31
|
+
|
32
|
+
Message.reads_count
|
33
|
+
=> 1
|
34
|
+
|
35
|
+
Message.unreads_count
|
36
|
+
=> 1
|
37
|
+
|
38
|
+
Message.mark_all_as_read
|
39
|
+
=> [#<Message id: 2, read_at: Tue, 28 Nov 2017 08:04:44 UTC +00:00>]
|
40
|
+
|
41
|
+
Message.mark_all_as_unread
|
42
|
+
=> [#<Message id: 1, read_at: nil>,
|
43
|
+
#<Message id: 2, read_at: nil>]
|
44
|
+
|
45
|
+
|
46
|
+
# Instance methods
|
47
|
+
|
48
|
+
message.mark_as_read
|
49
|
+
=> true
|
50
|
+
message
|
51
|
+
=> #<Message id: 1, read_at: Tue, 28 Nov 2017 08:10:20 UTC +00:00>
|
52
|
+
message.read?
|
53
|
+
=> true
|
54
|
+
message.unread?
|
55
|
+
=> false
|
56
|
+
|
57
|
+
message.mark_as_unread
|
58
|
+
=> true
|
59
|
+
message
|
60
|
+
=> #<Message id: 1, read_at: nil>
|
61
|
+
message.read?
|
62
|
+
=> false
|
63
|
+
message.unread?
|
64
|
+
=> true
|
65
|
+
```
|
66
|
+
|
67
|
+
## Installation
|
68
|
+
Add this line to your application's Gemfile:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
gem 'shiroyagi'
|
72
|
+
```
|
73
|
+
|
74
|
+
And then execute:
|
75
|
+
```bash
|
76
|
+
$ bundle
|
77
|
+
```
|
78
|
+
|
79
|
+
Or install it yourself as:
|
80
|
+
```bash
|
81
|
+
$ gem install shiroyagi
|
82
|
+
```
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
Contribution directions go here.
|
86
|
+
|
87
|
+
## License
|
88
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Shiroyagi'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
data/lib/shiroyagi.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Shiroyagi
|
2
|
+
module ActsAsShiroyagi
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
# TODO: The read_at column name should be customizable via an argument.
|
7
|
+
def acts_as_shiroyagi(options = {})
|
8
|
+
end
|
9
|
+
|
10
|
+
def reads_count
|
11
|
+
reads.count
|
12
|
+
end
|
13
|
+
|
14
|
+
def unreads_count
|
15
|
+
unreads.count
|
16
|
+
end
|
17
|
+
|
18
|
+
def mark_all_as_read
|
19
|
+
unreads.update(read_at: Time.current)
|
20
|
+
end
|
21
|
+
|
22
|
+
def mark_all_as_unread
|
23
|
+
reads.update(read_at: nil)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
included do
|
28
|
+
scope :reads, -> { where.not(read_at: nil) }
|
29
|
+
scope :unreads, -> { where(read_at: nil) }
|
30
|
+
|
31
|
+
def mark_as_read
|
32
|
+
update(read_at: Time.current) if unread?
|
33
|
+
end
|
34
|
+
|
35
|
+
def mark_as_unread
|
36
|
+
update(read_at: nil) if read?
|
37
|
+
end
|
38
|
+
|
39
|
+
def mark_as_read!
|
40
|
+
update!(read_at: Time.current) if unread?
|
41
|
+
end
|
42
|
+
|
43
|
+
def mark_as_unread!
|
44
|
+
update!(read_at: nil) if read?
|
45
|
+
end
|
46
|
+
|
47
|
+
def read?
|
48
|
+
read_at.present?
|
49
|
+
end
|
50
|
+
|
51
|
+
def unread?
|
52
|
+
read_at.blank?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shiroyagi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rui Onodera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: factory_bot_rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Read/Unread status management module for Rails.
|
84
|
+
email:
|
85
|
+
- deraru@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/shiroyagi.rb
|
94
|
+
- lib/shiroyagi/acts_as_shiroyagi.rb
|
95
|
+
- lib/shiroyagi/version.rb
|
96
|
+
- lib/tasks/shiroyagi_tasks.rake
|
97
|
+
homepage: https://github.com/Findy/shiroyagi
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.13
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Read/Unread status management module for Rails.
|
121
|
+
test_files: []
|