Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
滅・サービスクラス🔥 / Destruction Service Class
Search
Takumi Shotoku
February 13, 2025
Technology
8
2k
滅・サービスクラス🔥 / Destruction Service Class
【オフライン開催】Roppongi.rb #27
https://roppongirb.connpass.com/event/343872/
Takumi Shotoku
February 13, 2025
Tweet
Share
More Decks by Takumi Shotoku
See All by Takumi Shotoku
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
220
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
260
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
9
2.7k
Let's get started with Ruby && Rails Tips
sinsoku
0
410
LTの敷居を下げる / Lower the threshold for LT
sinsoku
1
360
CircleCIの高速化🚀 / CircleCI faster
sinsoku
3
1.3k
Railsアプリと型検査 / Rails app and type checking
sinsoku
5
1.5k
💎のつくりかた 2023 / How to make gems 2023
sinsoku
2
370
Make tests run faster
sinsoku
2
700
Other Decks in Technology
See All in Technology
RAGの基礎から実践運用まで:AWS BedrockとLangfuseで実現する構築・監視・評価
sonoda_mj
0
410
問題解決に役立つ数理工学
recruitengineers
PRO
3
110
Compose MultiplatformにおけるiOSネイティブ実装のベストプラクティス
enomotok
1
190
モジュラーモノリスでスケーラブルなシステムを作る - BASE のリアーキテクチャのいま
panda_program
7
1.9k
Explainable Software Engineering in the Public Sector
avandeursen
0
300
fukuoka.ts #3 社内でESLintの共通設定を配りたい2025年春版
pirosikick
1
280
ソフトウェア開発におけるインターフェイスという考え方 / PHPerKaigi 2025
k1low
9
3.8k
IAMのマニアックな話 2025 ~40分バージョン ~
nrinetcom
PRO
4
670
AIエージェント完全に理解した
segavvy
4
220
目次機能実装から理解するLexical Editor
wtdlee
0
130
Symfony in 2025: Scaling to 0
fabpot
2
110
SLI/SLO・ラプソディあるいは組織への適用の旅
nwiizo
4
1.1k
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
Git: the NoSQL Database
bkeepers
PRO
429
65k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
8
700
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.4k
We Have a Design System, Now What?
morganepeng
51
7.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
134
33k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
Typedesign – Prime Four
hannesfritz
41
2.6k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
Writing Fast Ruby
sferik
628
61k
Scaling GitHub
holman
459
140k
Transcript
໓ɾαʔϏεΫϥε Roppongi.rb #27 2025/02/13 1
ࣗݾհ • ໊લ: ਖ਼ಙ (aka: ਆ) • GitHub: @sinsoku (ը૾ӈ্)
• X: @sinsoku_listy (ը૾ӈԼ) • Railsྺ: 10͘Β͍ 2
એ: ! sinsoku/rbs-trace • ςετͷ࣮ߦ࣌ʹܕใΛऩू • ࣗಈతʹ rbs-inline ͷίϝϯτΛૠೖ •
։ൃதʢmain ϒϥϯνͷར༻Λਪʣ 3
αʔϏεΫϥεʹ͍ͭͯ 4
αʔϏεΫϥεͱ • αʔϏεͷػೳΛදݱ͢ΔΫϥε • ෳϞσϧΛѻ͏Ϋϥε • ϏδωεϩδοΫΛѻ͏Ϋϥε • υϝΠϯۦಈʢDDDʣ 5
2025-02-12 6
2024-11-05 7
2023-10-05 8
2022-03-30 9
αʔϏεΫϥεΛ࡞Βͳ͍ٕज़ 10
! FormObjectʹΑΔΞϓϩʔν RailsͷΈΛཧղͯ͠ϞσϧΛ্खʹҭͯΔ1 by igaiga 1 https://speakerdeck.com/igaiga/kaigionrails2024/ 11
⭐ ผख๏: ActiveRecord::Callbacks Λ͏ • 1ͭͷτϥϯβΫγϣϯʹͳΔ • before_validation ͔ΒτϥϯβΫγϣϯʹؚ·ΕΔ2 •
ϞσϧʹϩδοΫ͕ू͞ΕΔ • Immutable Data Model લఏͰઃܭ͢Δ 2 SQLΛൃߦ͠ͳ͍߹τϥϯβΫγϣϯͷ։࢝Ԇ͞ΕΔ 12
ྫ: Ϣʔβʔ͕ୀձ͢Δʢཧআʣ 13
NG: UserArchiveServiceΛ࡞Δ class UsersController # POST /users/:id/archive def archive service
= UserArchiveService.new(current_user) if service.call head :ok else head :bad_request end end end 14
NG: UserArchiveServiceΛ࡞Δ class UserArchiveService validate :unpaid_fees_must_not_exist def initialize(user) @user =
user end def call ActiveRecord:"Base.transaction do # `users.deleted_at` ʹݱࡏ࣌Λอଘ # ؔ࿈͢ΔσʔλΛߋ৽͢Δ end end end 15
OK: ArchiveϞσϧΛ࡞Δ class ArchivesController def create archive = Archive.new(user: current_user)
if archive.save head :ok else head :bad_request end end end 16
OK: ArchiveϞσϧΛ࡞Δ class Archive < ApplicationRecord belongs_to :user validate :unpaid_fees_must_not_exist
after_create :set_deleted_at, :update_related_data private def set_deleted_at user.update!(archived_at: Time.current) end def update_related_data # ؔ࿈͢ΔσʔλΛߋ৽͢Δ end end 17
OK: ArchiveϞσϧΛ࡞ΔʢActiveModel൛ʣ class Archive include ActiveModel:"Model extend ActiveModel:"Callbacks def initialize(user:)
@user = user end def save # ϝΠϯͷॲཧ end end 18
! ·ͱΊʢ͕࣌ؒΓͳ͔ͬͨ...ʣ • CallbacksΛ͏ͷѱ͘ͳ͍ • accepts_nested_attributes_for ͷར༻ѱ͘ͳ͍ • ͨͩ͠ Immutable
Data Model Λҙࣝ͢Δ • 1ͭͷϞσϧʹ Callbacks ͕ଟ͘ͳΓෳࡶʹͳΔͨΊ ଓ͖࠙ձͰ͠·͠ΐ͏ !" 19