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
6
1.6k
滅・サービスクラス🔥 / 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
190
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
250
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
9
2.6k
Let's get started with Ruby && Rails Tips
sinsoku
0
390
LTの敷居を下げる / Lower the threshold for LT
sinsoku
1
350
CircleCIの高速化🚀 / CircleCI faster
sinsoku
3
1.3k
Railsアプリと型検査 / Rails app and type checking
sinsoku
5
1.4k
💎のつくりかた 2023 / How to make gems 2023
sinsoku
2
360
Make tests run faster
sinsoku
2
680
Other Decks in Technology
See All in Technology
アジャイル開発とスクラム
araihara
0
170
Developers Summit 2025 浅野卓也(13-B-7 LegalOn Technologies)
legalontechnologies
PRO
0
500
データの品質が低いと何が困るのか
kzykmyzw
6
1.1k
次世代KYC活動報告 / 20250219-BizDay17-KYC-nextgen
oidfj
0
150
室長と気ままに学ぶマイクロソフトのビジネスアプリケーションとビジネスプロセス
ryoheig0405
0
350
データマネジメントのトレードオフに立ち向かう
ikkimiyazaki
3
300
RSNA2024振り返り
nanachi
0
530
利用終了したドメイン名の最強終活〜観測環境を育てて、分析・供養している件〜 / The Ultimate End-of-Life Preparation for Discontinued Domain Names
nttcom
1
120
7日間でハッキングをはじめる本をはじめてみませんか?_ITエンジニア本大賞2025
nomizone
2
1.7k
個人開発から公式機能へ: PlaywrightとRailsをつなげた3年の軌跡
yusukeiwaki
11
2.9k
Helm , Kustomize に代わる !? 次世代 k8s パッケージマネージャー Glasskube 入門 / glasskube-entry
parupappa2929
0
210
Oracle Cloud Infrastructure:2025年2月度サービス・アップデート
oracle4engineer
PRO
1
140
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
44
13k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Unsuck your backbone
ammeep
669
57k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Six Lessons from altMBA
skipperchong
27
3.6k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Code Reviewing Like a Champion
maltzj
521
39k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
YesSQL, Process and Tooling at Scale
rocio
171
14k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
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