-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minor-feat: any column can be specified #51
Conversation
rspecの結果 F-00168-Mac: ~/workspace/shiroyagi (feat/any_column_can_be_specified %=)
Randomized with seed 52170
*................................................................................................................................
Pending: (Failures listed here are expected and do not affect your suite's status)
1) User add some examples to (or delete) /Users/kota.nakatsubo/workspace/shiroyagi/spec/models/user_spec.rb
# Not yet implemented
# ./spec/models/user_spec.rb:4
Finished in 0.91994 seconds (files took 2.45 seconds to load)
129 examples, 0 failures, 1 pending
Randomized with seed 52170 |
@@ -0,0 +1,417 @@ | |||
require 'rails_helper' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストの中身は以下をコピーして、カラム、モデル名を変更しただけ
spec/models/message_spec.rb
lib/shiroyagi/acts_as_shiroyagi.rb
Outdated
# NOTE: override this method change column to use read management | ||
def read_management_column_name | ||
:read_at | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARの self.table_name = :hoge
みたいな感じで設定できた方が良さそうです
シンプルに書けばこんな感じ?
def read_management_column_name
@read_management_column_name
end
def read_management_column_name=(column_name)
@read_management_column_name = column_name
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
もしくはdeviseの devise :hoge
を参考に、 acts_as_shiroyagi read_management_column_name: :hoge
みたいな?
https://github.com/heartcombo/devise/blob/main/lib/devise/models.rb#L71-L111
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satom9to5
5c43143
で修正しました
シンプル方針で
lib/shiroyagi/acts_as_shiroyagi.rb
Outdated
|
||
def mark_as_read | ||
update(read_at: Time.current) if unread? | ||
update(self.class.read_management_column_name => Time.current) if unread? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下のprivate method追加した方が見やすいかと
def read_management_column_name
self.class.read_management_column_name
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satom9to5
bf58746
で修正しました
lib/shiroyagi/acts_as_shiroyagi.rb
Outdated
end | ||
|
||
def read? | ||
read_at.present? | ||
send(self.class.read_management_column_name).send('present?') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send(self.class.read_management_column_name).send('present?') | |
send(self.class.read_management_column_name).present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satom9to5
6b1e611
で修正しました
lib/shiroyagi/acts_as_shiroyagi.rb
Outdated
def acts_as_shiroyagi(options = {}) | ||
@read_management_column_name = options[:column].to_sym |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@read_management_column_name = options[:column].to_sym | |
@read_management_column_name = options[:column].to_sym if options[:column].present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
24c3613
こちらで
@deraru さんにも見てもらったほうがいいですね。 |
@deraru |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README の更新もお願いします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
任意のカラムを既読管理用に指定できるようにしました
デフォルトは
read_at
です