Skip to content
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

Merged
merged 9 commits into from
Jul 29, 2022

Conversation

2bo
Copy link
Contributor

@2bo 2bo commented Jul 26, 2022

任意のカラムを既読管理用に指定できるようにしました
デフォルトはread_atです

@2bo
Copy link
Contributor Author

2bo commented Jul 26, 2022

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'

Copy link
Contributor Author

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

@2bo 2bo requested a review from satom9to5 July 26, 2022 06:25
Comment on lines 9 to 12
# NOTE: override this method change column to use read management
def read_management_column_name
:read_at
end
Copy link
Member

@satom9to5 satom9to5 Jul 26, 2022

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satom9to5
5c43143
で修正しました

シンプル方針で

@2bo 2bo changed the title any column can be specified minor-feat: any column can be specified Jul 26, 2022

def mark_as_read
update(read_at: Time.current) if unread?
update(self.class.read_management_column_name => Time.current) if unread?
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satom9to5
bf58746
で修正しました

end

def read?
read_at.present?
send(self.class.read_management_column_name).send('present?')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
send(self.class.read_management_column_name).send('present?')
send(self.class.read_management_column_name).present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satom9to5
6b1e611
で修正しました

def acts_as_shiroyagi(options = {})
@read_management_column_name = options[:column].to_sym
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@read_management_column_name = options[:column].to_sym
@read_management_column_name = options[:column].to_sym if options[:column].present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24c3613
こちらで

@2bo 2bo requested a review from satom9to5 July 26, 2022 08:01
@satom9to5
Copy link
Member

@deraru さんにも見てもらったほうがいいですね。

@2bo 2bo requested a review from deraru July 26, 2022 08:24
@2bo
Copy link
Contributor Author

2bo commented Jul 26, 2022

@deraru
こちらレビューをお願いします🙏

Copy link
Contributor

@deraru deraru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README の更新もお願いします。

@2bo
Copy link
Contributor Author

2bo commented Jul 27, 2022

@deraru
こちらで追記しました!
9ae560c

Copy link
Contributor

@deraru deraru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@2bo 2bo merged commit e27ac89 into master Jul 29, 2022
@2bo 2bo mentioned this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants