2020å¹´1æä»ãã§å ¥ç¤¾ãã社é·å®¤ ã¨ã³ã¸ãã¢ã®èç°ã¨ç³ãã¾ãã 社é·å®¤ã§ã¯kakariã¨ããããããã¤ãè¬å±åãæ¯æ´ãããµã¼ãã¹ããã£ã¦ããããã¡ãã§ãµã¼ãã¼ãµã¤ãã¨ã³ã¸ãã¢ã¨ãã¦åãã¦ãã¾ãã
ã¨ã³ã¸ãã¢ã¨ãã¦ã®ãã£ãªã¢ã¯ã¡ããã¢ã§2社ç®ã§ãã¾ã ã¾ã åå¼·ä¸ã®èº«ã§ãã ä»åã¯ã¡ããã¢ã§ã®éçºãå§ãã¦ãéçºç°å¢ã®ããã¨ãããå®è£ ã®tipsãä¸é¨ãç´¹ä»ãããã¨æãã¾ãã
éçºç°å¢ã®ããã¨ãã
CIã§RSpecãRubocopãã¯ããã¨ããè¤æ°ã®Lintð®ãéã£ã¦ããªãã¨ååãã¼ã¸ã§ããªã
Rubyã¯èªç±ãªè¨æ³ãã§ããã¡ãªããã®åé¢ã§ãè¨æ³ã®ã°ãã¤ããæ¯è¼çåºãã¡ã§ããããã¯ãLintã«ãã£ã¦ããç¨åº¦ã«ãã¼ãããã¨ãå¯è½ã§ãã
ã¾ããClassLength
ã»LineLength
ã»AbcSize
çã«ãã£ã¦ããã¡ã¤ã«ã®è¥å¤§ã»ã³ã¼ãã®è¤é度åããç¥ããã¨ãã§ãã¾ãã
kakariã§ã¯ClassLength 100è¡ä»¥ä¸ã¯ãã¹ã¿ã¼ãã¼ã¿ã§ã¯ãªãéã許å¯ãã¦ããªãã®ã§ãèªãã®ã諦ããããªããã¡ã¤ã«ã¯ç¡ãã§ãã
Dangerã使ããä»ã®ãã¡ã¤ã«ã¨åããã¦ããæ¸ãã¦ã»ããã¨ããã¬ãã¥ã¼æ¼ããç¡ããã¦ãã
ä¾ãã°ããã«ãªã¯ã¨ã¹ããåºããéã«ãXXX.created_at.strftime('%Y/%m/%d %H:%M')
ããã¼ã å
ã§ã¯l(XXX.created_at, format: :datetime_with_slash)
ã¨æ¸ãã¦ã»ããæã«ãDangerã§è¨å®ãã¦ããã¨èªåã§è¦åãåºãã¦ããã¾ãã
API~ããã³ãã¨ã³ãéã§éçºåã«OpenAPIã使ã£ã¦ãéããã©ã¡ã¼ã¿ã¨æå¾ ããã¬ã¹ãã³ã¹ã決å®ãã¦ãã
yamlãæ¸ãã ãã§Swagger Editorä¸ãChromeã®æ¡å¼µã§ãªãããªUIã®APIä»æ§æ¸ãèªåçæãã¦ãããããcommitteeã使ã£ã¦ãOpenAPIã§å®ç¾©ããã¬ã¹ãã³ã¹ãRspecã§èªåãã§ãã¯ãã¦ãããããã¾ãðª
kakariã®ã¡ã³ãã¼ã以åä½æããè³æãããã¾ãã®ã§ããèå³ããæ¹ã¯ä½µãã¦ç¢ºèªãé¡ããã¾ãã
å¯è½ãªéãããã©ã¼ãã³ã¹ã®è¯ãæ¸ãæ¹ãæ±ããããã
bulletã§ãã¹ãæã«N+1ãæ¤ç¥ããããç¡é§ãªç¹°ãè¿ãå¦çãã§ããã ãæ¸ããæ¸ãæ¹ãæ±ãããã¾ãã
ä¾ãã°ã対象ã¨ãªãæ£è
ãæ¢ããã¸ãã¯ãæ¸ãããæãaccount.patients.not_deleted.select do |patient|
ã ã¨è«çåé¤ããã¦ããªãæ£è
å
¨ä½ãåå¾ããæ£è
æ°åç¹°ãè¿ãåãã¦ãã¾ãæ£è
æ°ãå¤ãã»ã©ããã©ã¼ãã³ã¹ãæªããªãã¾ãã
ãã®å ´åãwhere
ãfind
ã¡ã½ããã使ã£ã¦ä¸æ°ã«å¯¾è±¡æ£è
ãæ¤ç´¢ããããã«ãããã¨ãæã¾ããã§ãã
ã¾ããé¢é£ä»ããããå¤ããã£ãã·ã¥ãããã£ããããã¼ãã«å士ãjoinããã£ãã·ã¥ããå¿
è¦ãããå ´åã¯ãeager_load
ãpreload
ã¡ã½ãããé©åã«ä½¿ãããã«ãã¦ãã¾ãã
ãã¹ãããã£ããæ¸ãã¦ãã
å ¥ç¤¾ããåã®ç§ã¯ã©ã¡ããã¨ããã¨ãã¹ãã¯æ¸ããããã©ã¦ã¶ã§åä½ç¢ºèªããã¦ãã¾ããããããããã¹ãããªãç°å¢ã§ã¯ããã¼ã¸ã§ã³ã¢ããããªãã¡ã¯ã¿ãªã³ã°ãè¾ãã£ãããåä½ãè¦ä»¶éãã«ãªã£ã¦ããã ã(è¡ãé·ãã£ããå¼æ°ãå¤ã)ã®ã¡ã½ãããæ¸ããã¡ã§ãã
ç¹ã«ã¬ãã¥ã¼ãä»æ§è¿½å ã«ãã£ã¦ãã³ã¼ããå¤æ´ããéã常ã«è¦ä»¶éãã®ãã§ãã¯ãæ¯åããã®ãï¼ã¨ãªãããã¹ããæ¸ããªãã£ãå·¥æ°åãå¾ã§ç¢ºèªå·¥æ°å¢å ããã°ã¬ã¨ãã¦éãããã£ã¦ãã¾ãã
社å å ¨ä½ã§ãã¹ãããã£ããæ¸ãç¿æ £ã¨ãªã£ã¦ãããããkakariã§ã¯ææ°ã®Rails6ç³»ãRuby 2.7ç³»ã使ã£ã¦ãããä»ã®ä¾åã©ã¤ãã©ãªã常ã«ã¢ãããã¼ãããã¦ãã¾ããã¾ãããªãã¡ã¯ã¿ãªã³ã°ç³»ã®issueã«ã¯ãã¹ããæ¢ã«æ¸ããã¦ãããããæ¸ããæ¬äººä»¥å¤ã§ãçæããããããã«ãªã£ã¦ãã¾ãã
å®è£ ã®tips
ãã¬ã¼ã³ãªRubyãã¡ã¤ã«ã§æ¸ãããPOROã§ãã¸ãã¯ããã¾ãã«åãåºã
ç§ã¯ã¾ã¨ã¾ã£ããã¸ãã¯ãå¿ è¦ã«ãªã£ãæãã¢ãã«å´ã«ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããã¯ã©ã¹ã¡ã½ãããæ¸ãã¦å®è£ ããã¡ã§ããããããããã¸ãã¯ãã¢ãã«ã«éä¸ããã¨ãé¢å¿äºãå ¥ãä¹±ãã¦ãã¹ããè¾ãã³ã¼ãã«ãªããã¡ã§ãã
kakariã§ã¯Foo::Updater
ã®ãããªã¯ã©ã¹ãåããã¯ã©ã¹ã¡ã½ããã§callãããã¨ãå¤ãã§ãã-er(~ãã人)ãå¼ã°ãã(call)ã¨ããååã ã¨ãã¡ã½ããåã«æ©ã¾ããã«ãããèªã¿æå´ã®é ã«ãå
¥ã£ã¦ãããããã¨æãã¾ãã
class Foo::Updater def self.call(params:) new(params).call end def initialize(params) @params = params end def call update end private attr_reader :params def update # ä½ãã®å¦ç end end
POROã«é¢ãã¦ã¯å¼ç¤¾ã®æè¡é¡§åã§ãã@willnetãããæ¸ããè¨äºãããã¾ãã®ã§ããèå³ããæ¹ã¯ä½µãã¦ç¢ºèªãé¡ããã¾ãã
ç¹°ãè¿ãåç §ãããã¡ã½ããã¯å¤æ°ã«æ ¼ç´ãã
2度ç®ãåç
§ããããã¸ãã¯ã®å ´åãçµæãå¤æ°ã«æ ¼ç´ãã¦ãã¾ããååã¯ã¤ã³ã¹ã¿ã³ã¹å¤æ°ãnil
ã«ãªãã®ã§ãå³å´ã®å¼ãå®è¡ããã¾ãã
2度ç®ä»¥éã®å®è¡ã§ã¯å¤æ°ã使ãããã®ã§ã2度ç®ä»¥éã«å¼æ°ãå¤ãã¦ç°ãªãçµæãåå¾ãããå ´åã¯æå³ããªãæåã«ãªãã®ã§æ³¨æãã¦ãã ããã
def foo_object @foo_object ||= Foo::Creator.call end
åæåã§ä½¿ãããã«ã©ã ã¯ããã©ã«ãå¤ãDBå´ã§å®ç¾©ããã®ã§ã¯ãªããã¢ãã«å´ã§å®ç¾©ãã
enumerizeã使ãå ´åãã¢ãã«ã«ããã©ã«ãå¤ãæã¤ãã¨ãå¯è½ã§ããã¡ãªããã¨ãã¦ãé ç®ãå¢ããã¨ãã«ããã©ã«ãã®å¤ãå¤ãããéãmigrateãã¡ã¤ã«ãçºè¡ããã«æ¸ã¿ã¾ããã¾ãtextã§æå®ã§ããã®ã§ãä½ã®å¤ãããã©ã«ãã«ãã¦ããããæ確ã§ãã
class CreateFooBars < ActiveRecord::Migration[6.0] def change create_table :foo_bars do |t| t.integer :age_code, default: 4 t.timestamps end end end
ã§ã¯ãªããä¸è¨ã®ããã«ã¢ãã«å´ã§å®ç¾©ããã
class Foo < ApplicationRecord extend Enumerize enumerize :age_code, in: { all: 0, older_forty: 1, older_fifty: 2, older_sixty: 3, older_sixty_five: 4, older_seventy: 5, older_seventy_five: 6, older_eighty: 7 }, default: :older_sixty_five end
ååã®éè¤ã®ãªãé¢é£ä»ãã®åç §ããã
ä¾ãã°ã¢ãã«ã¨ãã¦ã¯foo_answer
ãfoo_question
ã§ç¤ºãããããé¢é£ä»ãããéã«ã¯ãããã©ã«ãã§foo_answer.foo_question
ã¨ãªã£ã¦foo
ãåé·ã§ãã
Railsã®ããã©ã«ãã®inverse_of
ããå¤ãã¦foo_answer.question
ãfoo_question.answers
ã¨ãããæã¯inverse_of
ãæ示çã«è¨å®ãã¾ãã
class FooQuestion < ApplicationRecord has_many :answers, class_name: 'FooAnswer', dependent: :destroy, foreign_key: :question_id, inverse_of: :question end
class FooAnswer < ApplicationRecord belongs_to :question, class_name: 'FooQuestion', inverse_of: :answers end
Viewã§ãã使ããªãæ´å½¢ç¨ã®ã¡ã½ããã¯Decoratorã«åãåºã
erbãHamlã§å®è£ ãã¦ããç®æã¯Decoratorã使ã£ã¦viewã«ãã¸ãã¯ãç´æ¥æ¸ããªãããã«ãã¦ãã¾ã
module FooDecorator def full_name "#{last_name}ã#{first_name}" end end
ãããã«
ç§ã¯ä»ã¾ã§ã®èãæ¹ã¨ãã¦ãã¹ãã¼ããåªå ããã¨ãã¯ããç¨åº¦æ±ãç¶æ ã®ã³ã¼ãããªãªã¼ã¹ãããã®ã¯ä»æ¹ããªãã¨æã£ã¦ãã¾ãããããããã¡ããã¢ã§ã¯ãã¸ãã¹ã®ã¹ãã¼ãæãç ç²ã«ãããããã¦ãã³ãã¯ã¼ã«ãé ¼ããã便å©ãªã©ã¤ãã©ãªã§è³¢ãä»çµã¿åãã¦ãã³ã¼ãã®å質ãè½ã¨ããªãåãçµã¿ãå®è·µãã¦ããã¨ããé¨åã«è§¦ãããããã¨ããå ¥ç¤¾ãã¦è¯ãã£ãç¹ã®1ã¤ã§ãããªã®ã§ããã®ãããªéçºç°å¢ã§æé·ããã人ã«ã¨ã£ã¦ã¯ãã¡ããã¢ã¸ã®å ¥ç¤¾ã¨ããã®ã¯è¯ãé¸æè¢ã®ä¸ã¤ã ã¨æãã¾ããã
ä»åã¯ä»ã®è¨äºã¨æ¯ã¹ã¦1ã¤ã®äºé ãæ·±æãããå 容ã§ã¯ããã¾ããããããã使ã£ã¦ã¿ããããªãã»ãã¡ããã¢ã®éçºç°å¢ã®ãã¨ããã£ã¨ç¥ããããªãã¨æã£ã¦ããã ããå 容ã1ã¤ã§ãããã°å¹¸ãã§ãï¼èªãã§ããã ãããããã¨ããããã¾ããã
ã¡ããã¢ã§ã¯ä¸ç·ã«åã仲éãåéãã¦ãã¾ãã ãå¿åããå¾ ã¡ãã¦ããã¾ãï¼
â åéãã¸ã·ã§ã³ã¯ãã¡ã
https://medpeer.co.jp/recruit/entry/
â éçºç°å¢ã¯ãã¡ã
https://medpeer.co.jp/recruit/workplace/development.html