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
20150625_SpeeeTeckParty
Search
Tatsuya Sasaki
June 30, 2015
Technology
9
8.7k
20150625_SpeeeTeckParty
6/25に開催された、SpeeeTeckPartyで話したときに資料です。
Tatsuya Sasaki
June 30, 2015
Tweet
Share
More Decks by Tatsuya Sasaki
See All by Tatsuya Sasaki
20180912_小さな成功体験を積み重ねてチームで負債に立ち向かう_medbeer.pdf
sasata299
3
11k
Classi - Real Tech Night
sasata299
1
4.3k
20151129_Mroongaをとある教育サービスで導入してみた話
sasata299
0
4.8k
前回のMF Geeks Nightに参加してから実践したこと
sasata299
0
870
20141125_エンジニアドリブンな改善の進め方
sasata299
0
2.1k
20140926_VagrantとDockerと普段思ってること
sasata299
2
5.3k
20140219_4社合同技術勉強会
sasata299
2
4.1k
AngularJSを使ったらこんなことが出来るよ
sasata299
40
71k
エンジニア異種クラスタ交流会01
sasata299
0
2.2k
Other Decks in Technology
See All in Technology
CNAPPから考えるAWSガバナンスの実践と最適化
yuobayashi
4
480
メンバーがオーナーシップを発揮しやすいチームづくり
ham0215
2
340
Redmineの意外と知らない便利機能 (Redmine 6.0対応版)
vividtone
0
150
信頼性を支えるテレメトリーパイプラインの構築 / Building Telemetry Pipeline with OpenTelemetry
ymotongpoo
9
4.3k
ソフトウェアアーキテクトのための意思決定術: Software Architecture and Decision-Making
snoozer05
PRO
16
3k
第27回クラウド女子会 ~re:Invent 振り返りLT会~ 宣言型ポリシー、使ってみたらこうだった!
itkr2305
0
280
SIEMによるセキュリティログの可視化と分析を通じた信頼性向上プロセスと実践
coconala_engineer
1
2.5k
20250122_FinJAWS
takuyay0ne
2
350
RevOpsへ至る道 データ活用による事業革新への挑戦 / path-to-revops
pei0804
2
560
消し忘れリソースゼロへ!私のResource Explorer活用法
cuorain
0
120
20250129 Findy_テスト高活用化
dshirae
0
180
2025-01-24-SRETT11-OpenTofuについてそろそろ調べてみるか
masasuzu
0
140
Featured
See All Featured
BBQ
matthewcrist
85
9.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
260
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Building Adaptive Systems
keathley
39
2.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
39
1.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.6k
Optimising Largest Contentful Paint
csswizardry
33
3k
Transcript
3BJMT։ൃΛ͢Δ্Ͱ ͓͍ͬͯͨํ͕ྑͦ͞͏ͳ ̍̌ͷ͜ͱʢԾʣ 2015-06-25 @sasata299
ࣗݾհ w ͨͭ͞͞ w ώτϝσΟΞॴଐ w ͔Β͋͛ΤϯδχΞ w ٕज़ϒϩά
͔Β͋͛ ඒຯ͍͠
<13>ຊΛग़͠·ͨ͠
ͱ͍͏ࣄۀΛ͍ͬͯ·͢ɻ
ᶃ)BTIOFX\cI LcI<L>\^^ ᶄ'BU.PEFM ᶅ$PODFSO ᶆϓϨθϯςʔγϣϯ ᶇSBJMTDPOTPMFTBOECPY ᶈQMVDL ᶉpMUFS@QBSBNFUFST ᶊؔ࿈ͨ͠σʔλͷআ ᶋγϯάϧςʔϒϧܧঝʢ45*ʣ
ᶌJODMVEFͱQSFQFOE
ͬͱ͘ͱྑͦ͞͏ᶃ Hash.new { |h,k| h[k] = {} }
> hash = {} => {} > hash[:foo] => nil
> hash = Hash.new { |h,k| h[k] = {} }
=> {} > hash[:foo] => {} # nil͡Όͳ͍ʂ
> hash = Hash.new { |h,k| h[k] = {} }
=> {} > hash[:foo] => {} # nil͡Όͳ͍ʂ > hash[:foo][:bar] => nil > hash[:foo][:bar] = 1 => 1 > hash => { foo: { bar: 1 } }
ͬͱ͘ͱྑͦ͞͏ᶄ Fat Model
Fat Controller Fat Model ??? ୭͕௨Δಓ
Fat Controller Fat Model ??? ୭͕௨Δಓ ServiceΦϒδΣΫτ FormΦϒδΣΫτ, etc..
ͬͱ͘ͱྑͦ͞͏ᶅ Concern
ؔ৺ࣄΛͻͱ͔ͨ·Γʹͯ͠ཧ͢Δʂ
class Group before_save :set_default_name_if_need def post(comment); end end ! class
Message before_save :set_default_name_if_need def post(comment); end end ಉ͡Α͏ͳॲཧ͕͋Δ߹
module Commentable extend ActiveSupport::Concern ! included do before_save :set_default_name_if_need end
! def post(comment) Comment.create!(content: comment) end end
class Group include Commentable end ! class Message include Commentable
end εοΩϦ
ͬͱ͘ͱྑͦ͞͏ᶆ ϓϨθϯςʔγϣϯ
ϑϧωʔϜΛද͍ࣔͨ͠ʂ
module UserHelper def full_name(user) user.last_name + user.first_name end end VTFSΦϒδΣΫτΛ͢ͷΠέͯͳ͍
class User < ActiveRecord::Base def full_name last_name + first_name end
end 7JFXͰ͔͠Θͳ͍ͷʹϞσϧʹஔ͘ʁ
module UserDecorator def full_name last_name + first_name end end ྫ͑BDUJWF@EFDPSBUPSΛ͏
ͬͱ͘ͱྑͦ͞͏ᶇ $ rails console —sandbox
$ rails console —sandbox > user = User.first => #<User
id: 1, name: "sasata299", like: "karaage"> > user.like = "sushi" => "sushi" > u.save! => true
$ rails console —sandbox > user = User.first => #<User
id: 1, name: "sasata299", like: "karaage"> > user.like = "sushi" => "sushi" > u.save! => true > user = User.first => #<User id: 1, name: "sasata299", like: "sushi">
$ rails console > user = User.first => #<User id:
1, name: "sasata299", like: “karaage"> ࠶DPOTPMFΛ։͘ͱSPMMCBDL͞ΕͯΔ
$ rails console > user = User.first => #<User id:
1, name: "sasata299", like: “karaage"> > _ => #<User id: 1, name: "sasata299", like: “karaage"> ͪͳΈʹΞϯμʔείΞศརͰ͢
ͬͱ͘ͱྑͦ͞͏ᶈ pluck
ສ݅ͷ6TFSΛ༻ҙͯ͠JEͷҰཡΛऔಘ
Benchmark.bm 10 do |r| r.report “select” do User.select(:id).map(&:id) end r.report
“pluck” do User.pluck(:id) end end
user system total real select 16.290000 0.760000 17.050000 ( 20.753481)
pluck 4.350000 0.590000 4.940000 ( 6.712115) ഒҎ্͍ͧʂ
User.select(:id) [#<User id:1>, #<User id: 2>, …] ΦϒδΣΫτΛੜ NBQ JE
͢Δ [1, 2, …]
User.pluck(:id) [1, 2, …] ActiveRecordΦϒδΣΫτͷ ੜ͕ൃੜ͠ͳ͍͍ʂ
ͬͱ͘ͱྑͦ͞͏ᶉ filter_parameters
ͦͷ··ͩͱηΩϡΞͳใ͕ ϩάʹྲྀΕͯ͠·͏ʂʂʼʻ
Started POST "/users" Processing by UsersController#create as HTML Parameters: {"email"=>"
[email protected]
",
“password"=>"secret-value", “credit_card_number"=>"1111-2222-3333-4444"}
3BJMTBQQMJDBUJPODPOpHpMUFS@QBSBNFUFST <QBTTXPSE DSFEJU@DBSE@OVNCFS> pMUFS@QBSBNFUFSTΛઃఆ͢Δ
Started POST "/users" Processing by UsersController#create as HTML Parameters: {"email"=>"
[email protected]
",
"password"=>"[FILTERED]", “credit_card_number"=>"[FILTERED]"}
ͬͱ͘ͱྑͦ͞͏ᶊ ؔ࿈ͨ͠σʔλͷআ
class Blog < ActiveRecord::Base has_many :articles dependent: :destroy end #MPHΛআͨ͠Βؔ࿈͢Δ"SUJDMFআ͢Δ
EFMFUFͱEFTUSPZͷҧ͍ EFMFUF ୯७ʹ%&-&5&จ͕ൃߦ͞ΕΔ͚ͩ EFTUSPZ CFGPSF@EFTUSPZBGUFS@EFTUSPZ࣮ߦ͞ΕΔ EFQFOEFOUߟྀ͞ΕΔ
ͬͱ͘ͱྑͦ͞͏ᶋ γϯάϧςʔϒϧܧঝʢ45*ʣ
ྑ͘ࣅͨϞσϧҰͭͷςʔϒϧͰѻ͓͏ ! 'PPEϞσϧͱ%SJOLϞσϧྑ͘ࣅͯΔ͔Β QSPEVDUTςʔϒϧͰ·ͱΊͯѻ͓͏ʂతͳ
class Product < ActiveRecord::Base # typeΧϥϜΛ͍࣋ͬͯΔ͜ͱʂ end ! class Food
< Product; end class Drink < Product; end
Food.create! <#Food id: 1, type: "Food", …> ! 2.times {
Drink.create! } <#Drink id: 2, type: "Drink", …> <#Drink id: 3, type: "Drink", …>
mysql> SELECT id, type FROM products; ! +----+-------+ | id
| type | +----+-------+ | 1 | Food | | 2 | Drink | | 3 | Drink | +----+-------+
Food.all [#<Food id: 1, type: "Food", …>] ! Drink.all [#<Drink
id: 2, type: "Drink", …>, #<Drink id: 3, type: "Drink", …>] ! Product.all [#<Food id: 1, type: "Food", …>, #<Drink id: 2, type: "Drink", …>, #<Drink id: 3, type: "Drink", …>]
ͬͱ͘ͱྑͦ͞͏ᶌ include ͱ prepend
ҙͷϝιουΛੜ͍ͨ͠
class Bar include Foo end ! p Bar.ancestors # [Bar,
Foo, Object, …] #BSΫϥε͕༏ઌ͞ΕΔ
class Bar prepend Foo end ! p Bar.ancestors # [Foo,
Bar, Object, …] 'PPϞδϡʔϧ͕༏ઌ͞ΕΔ
JODMVEFͱQSFQFOEͷڍಈͷҧ͍ JODMVEF ݩͷΫϥεͷޙΖʹՃ͞ΕΔ ಉ໊ͷϝιουͷ߹ɺݩͷΫϥε͕༏ઌ͞ΕΔ QSFQFOE ݩͷΫϥεΑΓલʹՃ͞ΕΔ ಉ໊ͷϝιουͷ߹ɺϞδϡʔϧ͕༏ઌ͞ΕΔ
ᶃ)BTIOFX\cI LcI<L>\^^ ᶄ'BU.PEFM ᶅ$PODFSO ᶆϓϨθϯςʔγϣϯ ᶇSBJMTDPOTPMFTBOECPY ᶈQMVDL ᶉpMUFS@QBSBNFUFST ᶊؔ࿈ͨ͠σʔλͷআ ᶋγϯάϧςʔϒϧܧঝʢ45*ʣ
ᶌJODMVEFͱQSFQFOE
࠷ޙʹ
https://www.wantedly.com/companies/hitomedia ΤϯδχΞืूͯ͠·͢ʂ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ @sasata299