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
2.1k
滅・サービスクラス🔥 / 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
Automatically generating types by running tests
sinsoku
2
2.4k
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
230
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
270
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
10
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
380
Other Decks in Technology
See All in Technology
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
1
360
はてなの開発20年史と DevOpsの歩み / DevOpsDays Tokyo 2025 Keynote
daiksy
6
1.5k
AIで進化するソフトウェアテスト:mablの最新生成AI機能でQAを加速!
mfunaki
0
140
改めて学ぶ Trait の使い方 / phpcon odawara 2025
meihei3
1
650
Recap of Next - Google Cloud で実践する クラウドネイティブ最前線 / The Frontlines of Cloud-Native with Insights from Google Cloud
aoto
PRO
1
100
SREの視点で考えるSIEM活用術 〜AWS環境でのセキュリティ強化〜
coconala_engineer
1
290
Amazon CloudWatch Application Signals ではじめるバーンレートアラーム / Burn rate alarm with Amazon CloudWatch Application Signals
ymotongpoo
5
450
Devinで模索する AIファースト開発〜ゼロベースから始めるDevOpsの進化〜
potix2
PRO
7
3.3k
Micro Frontends: Necessity, Implementation, and Challenges
rainerhahnekamp
2
490
ブラウザのレガシー・独自機能を愛でる-Firefoxの脆弱性4選- / Browser Crash Club #1
masatokinugawa
1
450
Spring Bootで実装とインフラをこれでもかと分離するための試み
shintanimoto
7
790
プロダクト開発におけるAI時代の開発生産性
shnjtk
2
230
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Navigating Team Friction
lara
184
15k
A better future with KSS
kneath
239
17k
How to train your dragon (web standard)
notwaldorf
90
6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Producing Creativity
orderedlist
PRO
344
40k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
We Have a Design System, Now What?
morganepeng
52
7.5k
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