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
2
250
滅・サービスクラス🔥 / 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
240
"型"のある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
350
Make tests run faster
sinsoku
2
680
Other Decks in Technology
See All in Technology
Data-centric AI入門第6章:Data-centric AIの実践例
x_ttyszk
0
180
Larkご案内資料
customercloud
PRO
0
430
開発者が自律的に AWS Security Hub findings に 対応する仕組みと AWS re:Invent 2024 登壇体験談 / Developers autonomously report AWS Security Hub findings Corresponding mechanism and AWS re:Invent 2024 presentation experience
kaminashi
0
150
5分で紹介する生成AIエージェントとAmazon Bedrock Agents / 5-minutes introduction to generative AI agents and Amazon Bedrock Agents
hideakiaoyagi
0
170
依存関係があるコンポーネントは Barrel ファイルでまとめよう
azukiazusa1
3
490
CNAPPから考えるAWSガバナンスの実践と最適化
yuobayashi
5
780
AIプロダクト開発から得られた知見 - 2025年1月版
takaakikakei
0
180
Bounded Context: Problem or Solution?
ewolff
1
200
まだ間に合う! エンジニアのための生成AIアプリ開発入門 on AWS
minorun365
PRO
4
520
10分で紹介するAmazon Bedrock利用時のセキュリティ対策 / 10-minutes introduction to security measures when using Amazon Bedrock
hideakiaoyagi
0
140
日経電子版 x AIエージェントの可能性とAgentic RAGによって提案書生成を行う技術
masahiro_nishimi
1
220
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
10
120k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
29
2.2k
Documentation Writing (for coders)
carmenintech
67
4.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.4k
Facilitating Awesome Meetings
lara
51
6.2k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
RailsConf 2023
tenderlove
29
990
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