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.3k
滅・サービスクラス🔥 / 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
9.3k
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
240
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
290
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
10
2.8k
Let's get started with Ruby && Rails Tips
sinsoku
0
430
LTの敷居を下げる / Lower the threshold for LT
sinsoku
1
380
CircleCIの高速化🚀 / CircleCI faster
sinsoku
3
1.4k
Railsアプリと型検査 / Rails app and type checking
sinsoku
5
1.5k
💎のつくりかた 2023 / How to make gems 2023
sinsoku
2
410
Other Decks in Technology
See All in Technology
讓測試不再 BB! 從 BDD 到 CI/CD, 不靠人力也能 MVP
line_developers_tw
PRO
0
120
基調講演: 生成AIを活用したアプリケーションの開発手法とは?
asei
1
120
「伝える」を加速させるCursor術
naomix
0
610
New Cache Hierarchy for Container Images and OCI Artifacts in Kubernetes Clusters using Containerd / KubeCon + CloudNativeCon Japan
pfn
PRO
0
150
kotlin-lsp を Emacs で使えるようにしてみた / use kotlin-lsp in Emacs
nabeo
0
140
AIにどこまで任せる?実務で使える(かもしれない)AIエージェント設計の考え方
har1101
3
990
RubyOnRailsOnDevin+α / DevinMeetupJapan#2
ginkouno
0
230
Autonomous Database サービス・アップデート (FY25)
oracle4engineer
PRO
2
760
Long journey of Continuous Delivery at Mercari
hisaharu
1
200
脅威をモデリングしてMCPのセキュリティ対策を考えよう
flatt_security
4
1.5k
Cloud Native Scalability for Internal Developer Platforms
hhiroshell
2
430
QAはソフトウェアエンジニアリングを学んで実践するのが大事なの
ymty
1
370
Featured
See All Featured
BBQ
matthewcrist
89
9.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
900
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
The Pragmatic Product Professional
lauravandoore
35
6.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Why Our Code Smells
bkeepers
PRO
337
57k
KATA
mclloyd
29
14k
How GitHub (no longer) Works
holman
314
140k
Automating Front-end Workflow
addyosmani
1370
200k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
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