sharoa
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 【第30週】パRails輪読会🚂 \(2024\-03\-18\~ 2024\-03\-22\) ###### tags: `パRails🚂` - [開催概要](https://hackmd.io/4A_8ahJtQNi5hz713N5Y7w?view) - [パRails輪読会 ノートまとめ](https://hackmd.io/jsgA8Pf_RVioOgSL_VOR4g) - サンプルコード・正誤表:[サポートページ:パーフェクトRuby on Rails【増補改訂版】:|技術評論社](https://gihyo.jp/book/2020/978-4-297-11462-6/support) - **サンプルコードをダウンロードしただけでは、すぐに`rails s`できない可能性が高い**です。 以下のページに環境構築の手順をまとめたので、ドライバーをやってくださるという方は、こちらに沿って環境構築をお願いします🙏 ⏩ [環境構築の手順 2022年版](https://hackmd.io/y7qb2BRMT2Wd4tAtKYObcQ) ⏩ [環境構築の手順 2023年版](https://hackmd.io/3_lnn8_QRD6wEjwFbWcBzQ) 💁‍♀️ [更新の手順 2章編](https://hackmd.io/pZAmF2EjSmyQ38lUtJ_CqA) ## 目次 [TOC] ------ ## 2024\-03\-18(月) ### ファシリ @ayu-0505 ### ドライバー ### 読んだところ 13-2 「コールバックオブジェクト」から 13-2-4 510p の途中まで。 PR: ### 次回 13-2-4 510p 「▫️更新系の場合」から🚂 ### 学んだこと・感想 - @sharoa - モデルのコールバックは【コールバックを実装するブロック、コールバックを実装するメソッド名のシンボル、コールバックを実装するオブジェクト】のいずれかをbefore_saveをはじめとした各メソッドの引数に指定して呼び出すことで設定できて、そのうち最後のオブジェクトのことをコールバックオブジェクトと呼ぶらしい。 - このコールバックオブジェクトはモデルとは独立したクラウをとして定義されるため、複数のモデル間で再利用できる。 - コールバックオブジェクトを単独で利用するのではなく、Consernと一緒に使うことで色々と使いやすくなる?みたい。 - でも結局Consernだけでも同じことは実現できるって。わお。 - コールバックオブジェクトを利用すべきかという疑問が生まれることもあるらしい。Consernの時にも似たようなこと言ってたな〜と思いました。 - @ayu-0505 - コールバックオブジェクトとは、モデルとは独立したクラスとして定義されるオブジェクト。 - Concernsにまとめることでさらに共通化、抽象化することができる。(ただし、わかりにくさにも繋がる) - FBCのコードはこういう内容の現状における最適解が分かりそうで勉強になりそう - 久しぶりに参加できて嬉しかったです! @moegi29 - コールバックオブジェクトを今回の例ではmodelの中で使っているけどもっと共通化したい場合はconcernディレクトリの中で使うみたい - コールバックオブジェクトはブートキャンプアプリの中でも使われている。書き方を覚えておきたいと思いました - `__send__`と`send`は機能的には同じだけど再定義できる、できない部分で違いがある - tapメソッドはtapの前のオブジェクトをブロック引数に渡してブロックを渡せるメソッド - ついに明日最終回! - @sakanobu - リスト13.15,16の Concern の使い方がとてもなるほどなと思った - Model の before_save などのクラスメソッドの記述を手続き処理のかたまりと捉えることで、それらをリスト13.16で encrypt_attributes というメソッドで呼ぶ出せるように Concern を使えるというのはお〜となった - リスト13.17の __send__ は皆さんがいてくれたおかげで after_find と after_save の記述の簡略化だとやっと理解できたので輪読会っていいなぁと改めて思いました - @shodan - Concernが混じったコールバックオブジェクトのところはすみません、だいぶ雰囲気で読んでいました😅 - bootcampのコードとか、(必要になった時に)実際に見た方がピンときそうな気はします。 - bootcampのmodelsのディレクトリには「〜callbacks.rb」みたいなファイルがあるので、それらです。 - user_callbacksでは、新しいユーザーが生まれたら`after_save`で相談部屋を作ってました! https://github.com/fjordllc/bootcamp/blob/main/app/models/user_callbacks.rb - 最後の章はどれも単一のモデルの責務を超えるような複雑な内容をどうモデルから分離するか、ということがテーマになっていると思います。 - 今回でいえば複雑なコールバック。 - @motohiro-mm - コールバックオブジェクト:コールバックを実装するオブジェクト。 - コールバックのクラスを定義してコールバックオブジェクトを導入できる - 共通化して使える - コールバックオブジェクトをあちこちで定義すると保守性が低下するので、コールバックオブジェクト単独で利用せず、Concernと併用すると良い - フィヨルドアプリは単独っぽい(利用している部分が少ないから?) - `send`と`__send__`勉強になりました - `.tap{pp _1}`はメソッドがたくさんつながってるときに途中のselfが分かるので便利(そうにみなさん使ってました) - あとすこしでおわる!でも最後の最後まで難しい! - @sugiwe - コールバックを実装するオブジェクトのことをコールバックオブジェクトと呼ぶ。コールバックオブジェクトはmodelディレクトリとかにボンっと置いておいたりする - phone_numberを暗号化するメソッドをUserモデルに書いていた際、属性を暗号化するメソッドをUserモデルでなくコールバックオブジェクトに書くことで別のモデルでも再利用できるようになる - ただしそれだとまだUserモデルに少し記述が残っており、コールバックオブジェクトでなくConcernとして抽出することで完璧に分離できる。ふむふむ…? - `tap`メソッド、使いこなしたい - `send`と`__send__`は動作としては同じっぽいけど`send`は再定義できてしまうので、知らぬところで再定義されている可能性を考慮して`__send__`を使うと良いらしい…?(予約語みたいに(?)、再定義できなければいいのにとも思った…) - 「最後の章はどれも単一のモデルの責務を超えるような複雑な内容をどうモデルから分離する」わかりやすかったのでこちらにもメモ📝 ------ ## 2024\-03\-19(火) ### ファシリ @motohiro-mm ### ドライバー ### 読んだところ 13-2-4 510p 「▫️更新系の場合」から 520P 最後まで PR: ### 次回 終わり〜!🎉 ### 学んだこと・感想 - @sharoa - 更新系(データの暗号化など)のデータ操作(Create,Update,Delete)に関するロジックの場合の実装にはコールバックオブジェクトが利用できるが、参照系(木構造のデータ取得など)のデータ操作(Read)に関するロジックの場合にはコールバック自体が利用できない。 - Consernでも同じようなことはできるが、更新系は特に理由がない限りコールバックオブジェクトを利用した方が良い - 上にも書いたように参照系はコールバックが使えないので、Consernを利用すると良い。 - テストコードの件が難しすぎて、聞くことしかできなかったです。最後の最後まで難しすぎて流石だわって感じでしたw - 約7ヶ月のパrailsの輪読会でした。 - 私の体調不良でだいぶ日数を奪ってしまい本当に申し訳ないです。 - そして、みなさん最後までありがとうございました!! - @sugiwe - 更新系(Create、Update、Delete)に関するロジックの実装にはコールバックオブジェクトを使うことができる。 - 木構造=ツリー構造。階層構造のこと - 更新を伴わない操作、つまり参照系のデータ操作(Read)にはコールバックを使うことはできない。コールバックを呼び出すタイミングがないから。 - リスト13.18の読み解きがほとんどわからなくてフリーズしていましたが、とにかくフィナーレに参加できてよかったです😄 - パRails、1人だと確実に挫折していたので輪読会に参加できてよかったです、ありがとうございました◎ - Railsをまた復習するためにRailsチュートリアルあたりやってみようかな… - @moegi29 - 更新系のデータ操作に関するロジックの場合、テストがしやすいためコールバッグオブジェクトを使うと良い - コールバッグオブジェクトを使っているとmockでテストができる。mockはテスト用の空のオブジェクトのようなもの(sakanobuさんからの引用) - Concernでも同じことが実現できるけどテストダブルへの置き換えが難しく本物のオブジェクトを用いてテストするので大変 - パRails輪読会ついにフィナーレ!自分ひとりでは全く理解できなかった部分がたくさんありみなさんの議論を聞いて理解できた部分もたくさんありました。ありがとうございました!! - @shodan - チーム開発でもmockを触らなかったので、このあたりはふわっとしたままだな〜という感想。 - IssueによってはWebAPIのモックを作ったり触ったりするかも。 - パRails全体について - 3章くらいまでのところについて、なんだかんだ何度もパラパラめくり返して「おお〜」っとなったりしていたので、基本が全然身についていないんだな〜と思います。 - イベントアプリを作る流れでさらっと説明される便利メソッドとかよくあるパターンとかがたくさんあった気がするので、読み返して付箋を貼りたい。 - 12章以降のところは、いつか困ったら参照できるお守りという気持ちで今はいます(これでいいのかはわからない)。 - でも世の中のすごい人たちは大体この辺のことの知見をシェアしているような気もする。 - Action Cable, Action Textとかは使うことがなければ完全に忘れていきそう(使うことはあるのだろうか)。 - Active JobやRackあたりは引っ越しやら何やらで出れなかったんですが(この辺の方がむしろ大事そう)、おおまかに出席できて完走できて嬉しいです。 - @ayu-0505 - データの暗号化といった更新系データ操作ロジックの実装ではコールバックオブジェクトを利用できる - コールバックオブジェクトを使わず、Concernのみでも同じような実装はできるがテストのしやすさなどから、コールバックオブジェクトを使う方が良い - テストダブルとはテスト用に用意するダミー品。モックはその中でも出力を調査するために使用する。 - データ操作ロジックにおいてはコールバック自体が利用できない(それはそう)。この関係のロジックではConcernを利用する。 - 最初の方のパRails輪読会に参加できなかったのが悔やまれます、本当に参加できてよかったです! - @sakanobu - Concern 内でコールバックオブジェクトを利用するかの判断が、その Concern が before_save などの更新系なのかそれとも参照系なのかというのは言われて見れば単純明快な基準だなと思いました - mock についての Discord に書いた自分のメモなのですが、今読み返しても「変なこと書いちゃったな…」みたいな部分が多々あるので「ふーん?」みたいな参考程度で読んでくれるとありがたいです(後で修正しようと思います) - パRails輪読会には Docker あたりからの参加になってしまったのですが、ラジオ参加にもかかわらず皆さんが暖かく受け入れてくれたのでとても嬉しかったです!!本当にありがとうございました!! - @motohiro-mm - 更新系(create,update,delete)の場合はコールバックオブジェクトが利用できる - 参照系(read)はコールバックオブジェクトが利用できない - そもそもコールバック自体が利用できない、データ操作と関係ないから - コールバックオブジェクトを利用すると、テストダブル(モックとか)に置き換えられるのでテストが容易になる - コールバックオブジェクトを利用せずにConcernのみでやった場合は本物のオブジェクトを使ってテストするので手間がかかる - ぱRailsおわった!!!みなさんのおかげで最後までいけました!!!感謝です - @sadanora - コールバックオブジェクトとConcernどちらが適当か、データ操作が更新系か参照系かによって判断できる - 更新系の場合、コールバックオブジェクトの方が適当 - Concernでもできるけどコールバックオブジェクトの方がテストが楽になる - コールバックオブジェクトでは、自身を利用するオブジェクトが外から渡されるため、これらをテストダブルに置き換えることで容易にテストできる - Concernの場合テストダブルへの置き換えが難しく本物のオブジェクトを用意しないといけないので、コールバックオブジェクトを使う場合より手間がかかる - 参照系の場合、コールバックを伴わないのでConcernのが適当 - 完走おつかれさまでした!一人でちゃんと読みきれなかったので輪読会で最後まで読めて感謝です! - 今後も詰まった時にちょこちょこ開いて理解度を深めていきたいと思います ----- ## 2024\-03\-21(木) ### ファシリ ### ドライバー ### 読んだところ PR: ### 次回 ### 学んだこと・感想 ----- ## 2024\-03\-22(金) ### ファシリ ### ドライバー ### 読んだところ PR: ### 次回 ### 学んだこと・感想 -----

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully