LoginSignup
11
11

Rails 7.1でアプリ作成時にデフォルトで追加されるgemについて

Last updated at Posted at 2023-10-28

はじめに

私は2023年4月にRuby on Railsを学び始めた初学者で、主にRails5系を学んできました。

2023年10月11日にRails7.1.1がリリースされたこともあり、Rails7系での開発もしてみたい!ということで、事前調査としてRails7.1でRails newした場合にデフォルトで導入されるgemについて、どういったgemかを調べました。

各Gemについての説明は概要のみです。
詳細について気になる方は参考リンク先をご参照ください。

間違っている、あるいは正確でない情報が含まれている可能性があります。
ご指摘がある場合はコメントで教えていただけると幸いです。

実行環境

rbenv: 1.2.0
Ruby: 3.1.2
Bundler: 2.4.20
Ruby on Rails: 7.1.1
実行したコマンド rails new sample_app

Gemfile

長いので折りたたみにしています。

デフォルトで作成されるGemfile
source "https://rubygems.org"

ruby "3.1.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.1"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri windows ]
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"

  gem "error_highlight", ">= 0.4.0", platforms: [:ruby]
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
end

各Gemについて

rails

MVCパターンに従って、データベースを利用したWEBアプリケーションを作成するためのフルスタックWEBフレームワーク。DRY(Don’t Repeat Yourself)やCoC(Convention. over Configuration)を基本理念としており、既存のサービスではCookpadや食べログ、Hulu等がある。

# GitHub
Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

# RubyGems
Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.

GitHub:https://github.com/rails/rails
RubyGems:https://rubygems.org/gems/rails/versions/7.1.0

特徴・働き

  • LaravelやDjangoなど他言語のフレームワークと比較して昔からあるためサードパーティのライブラリ、ソフトウェア、gemが豊富にある
  • ActiveRecordやジェネレータなどデフォルトで用意された機能が多く、迅速な開発ができる
  • Stackshareによると2023年10月24日時点でStackOverflowの記事数やフォロワー数はDjangoやLaravelの方が多いが、Votes(投票)はRailsが一番多く、コミュニティが活発
  • 同じRubyのWebフレームワークであるSinatraと比較して、中〜大規模のWEBアプリケーション開発に向いている

参考リンク

Musclecoding | Ruby on Rails, Django, Laravel どのフレームワークがおすすめ?
netguru | Ruby on Rails vs Sinatra: Use the Right Web Framework for Your Next Project
Stackshare | Django vs Laravel vs Rails

sprockets-rails

Rails7.1においてはアセットパイプラインにおけるCSS・静的アセットの処理を担っているgem。
アセットのファイル結合やトランスパイル、最小化・難読化機能を持つ。

アセットパイプラインとは?
JavaScriptCSSアセットの配信を処理するためのフレームワークを提供します。(Ralisガイド v7.1より)
https://railsguides.jp/asset_pipeline.html
# GitHub
Provides Sprockets implementation for Rails 4.x (and beyond) Asset Pipeline.

# RubyGems
Sprockets Rails integration

GitHub:https://github.com/rails/sprockets-rails
RubyGems:https://rubygems.org/gems/sprockets-rails/versions/3.4.2

特徴・働き

  • 2007年からRailsに導入されていて、新たなモジュールやツールの発達に対応していないが、sprockets-railsによって簡単に実装ができ、シンプルにアセットをコンパイルできる
  • Node.js等の外部環境に依存しない
  • importmapとの組み合わせではトランスパイルに対応していないため、モダンなJavaScriptツール(ReactやNode.js系のツール)やTypeScriptに対応できない

参考リンク

https://www.wantedly.com/companies/wantedly/post_articles/354873
https://qiita.com/itkrt2y/items/18ea41828e1c22fc31e3
https://autovice.jp/articles/143
https://qiita.com/gobtktk/items/75e4eb2b223835da5663

sqlite3

RDBMSであるSQLite3を取り扱うためのGem

# RubyGems
Ruby library to interface with the SQLite3 database engine (http://www.sqlite.org). Precompiled binaries are available for common platforms for recent versions of Ruby.

RubyGems:https://rubygems.org/gems/sqlite3?locale=ja

特徴・働き

他のRDBMSと比較して、

  • 非常に軽量
  • 一般的なRDBMSは処理をサーバに任せる「クライアントサーバ型」
    それに対してSQLite3はアプリケーション内で処理する「組み込み型」
  • サーバーでのデータ共有には適さない

参考リンク

https://www.sqlite.org/index.html
https://bigdata-tools.com/sql-db/#1-3

puma

並列性の高いWEBサーバーで、マルチプロセス + マルチスレッドで動かす。

# GitHub
Puma is a simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications.

# RubyGems
Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. It's great for highly parallel Ruby implementations such as Rubinius and JRuby as well as as providing process worker support to support CRuby well.

GitHub:https://github.com/puma/puma
RubyGems:https://rubygems.org/gems/puma?locale=ja

特徴・働き

他のWEBサーバーと比較して、

  • 並列性が高いため処理が高速で、メモリを最大限活用できる
  • スロークライアントの影響を受けない
  • スレッドセーフ(複数の処理が同時に処理された場合でも不具合を生じない)でないと使用できない
  • スレッドの知識が必要になる

参考リンク

https://nekorails.hatenablog.com/entry/2018/10/12/101011
https://qiita.com/kompiro/items/223bb04c2f009787eea8
https://devcenter.heroku.com/ja/articles/deploying-rails-applications-with-the-puma-web-server


importmap-rails

トランスパイルやバンドルを用いず、ブラウザに直接JavaScriptモジュールをインポートする。

# GitHub
Import maps let you import JavaScript modules using logical names that map to versioned/digested files  directly from the browser.

# RubyGems
Use ESM with importmap to manage modern JavaScript in Rails without transpiling or bundling.

GitHub:https://github.com/rails/importmap-rails
RubyGems:https://rubygems.org/gems/importmap-rails?locale=ja

特徴・働き

  • 変更のあったJavaScriptファイル以外はキャッシュを利用できるため高速
  • nodeに依存しないアプリケーション開発ができる
  • sprocketsとの組み合わせではnodeに依存しないためトランスパイルが必要な場合には不向き

参考リンク

https://nekorails.hatenablog.com/entry/2018/10/12/101011
https://qiita.com/kompiro/items/223bb04c2f009787eea8
https://devcenter.heroku.com/ja/articles/deploying-rails-applications-with-the-puma-web-server

turbo-rails

Hotwire(サーバーサイドでHTMLを生成する仕組み)を構成する技術の一つ。
Turboを使用するとJavaScriptを記述せずに非同期処理を行うことができる。

# GitHub
Turbo gives you the speed of a single-page web application without having to write any JavaScript.

# RubyGems
The speed of a single-page web application without having to write any JavaScript.

GitHub:https://github.com/hotwired/turbo-rails
RubyGems:https://rubygems.org/gems/turbo-rails?locale=ja

特徴・働き

Turboは4つの技術から構成される

  • Turbo Drive
    • リンクやフォームのリクエストをfetchによる非同期処理に差し替える
    • headタグ内の要素は据え置きのままbodyタグ内の要素のみ置換する
    • headタグが置換されないのでCSSやJavaScriptが読み込まれたままにできる
  • Turbo Frames
    • Turbo Driveの部分置換版
    • bodyタグの指定した部分だけを置換する
    • 各置換の遅延読み込みができる
    • 必要なタグが少なく実装しやすい
  • Turbo Streams
    • Turbo Framesではできない、「フォームやリンク以外をトリガーとした置換」と「2箇所以上同時の置換」を可能にする
    • WebSocket上で動作する
    • 必要なタグが若干多い
  • Turbo Native
    • iOSやAndroidでTurboを使用するためのライブラリ

参考リンク

https://qiita.com/kazutosato/items/10a5bc04443d6b7e5bf8
https://zenn.dev/shita1112/books/cat-hotwire-turbo/viewer/abstract
https://mixandgo.com/learn/ruby-on-rails/turbo-frames-vs-turbo-streams
https://logmi.jp/tech/articles/324253

stimulus-rails

Turboと連携してHotwireの中核を担うJavaScriptのライブラリ。

# GitHub
Stimulus pairs beautifully with Turbo to provide a complete solution for fast, compelling applications with a minimal amount of effort. Together they form the core of Hotwire.

# RubyGems
A modest JavaScript framework for the HTML you already have.

GitHub:https://github.com/hotwired/stimulus-rails
RubyGems:https://rubygems.org/gems/stimulus-rails/versions/1.3.0

特徴・働き

  • 環境構築が不要
  • JavaScriptの記述量が減る
  • テストコードを書くのが難しい

参考リンク


jbuilder

JSON構造を宣言するためのDSL(ドメイン固有言語)を提供するgem。

# GitHub
Jbuilder gives you a simple DSL for declaring JSON structures that beats manipulating giant hash structures. This is particularly helpful when the generation process is fraught with conditionals and loops.

# RubyGems
Create JSON structures via a Builder-style DSL

GitHub:https://github.com/rails/jbuilder
RubyGems:https://rubygems.org/gems/jbuilder/versions/2.7.0

特徴・働き

  • JSON形式のデータを簡単に作成することができる
  • Railsにおいては@users = User.allなどで取得したデータをjson.array! @users, :name, :emailなどとすることで簡単にJSON形式に変換できる

参考リンク

https://pikawaka.com/rails/jbuilder
https://qiita.com/ryouzi/items/06cb0d4aa7b6527b3645


tzinfo-data

tzinfoが参照するタイムゾーン情報を提供するgem。(tzinfoはRubyからタイムゾーン情報を参照し、その情報に基づいて時間をコンバートするためのライブラリ。)

# GitHub
TZInfo::Data is the public domain IANA Time Zone Database packaged as a set of Ruby modules for use with TZInfo.

# RubyGems
TZInfo::Data contains data from the IANA Time Zone database packaged as Ruby modules for use with TZInfo.

GitHub:https://github.com/tzinfo/tzinfo-data
RubyGems:https://rubygems.org/gems/tzinfo-data/versions/1.2023.3?locale=ja

特徴・働き

  • tzinfo-dataはWindows環境でタイムゾーンを扱うためのgem。
    (LinuxベースのOSではtzinfoから直接システムのタイムゾーンにアクセスできるため不要)

参考リンク

https://qiita.com/tatama/items/3f0f5e42cb5f75b53817
https://k-koh.hatenablog.com/entry/2020/02/02/172126


bootsnap

Ruby/Railsのアプリを高速化するためのgem。

# GitHub
Bootsnap is a library that plugs into Ruby, with optional support for YAML and JSON, to optimize and cache expensive computations. See How Does This Work.

# RubyGems
Boot large ruby/rails apps faster

GitHub:https://github.com/Shopify/bootsnap
RubyGems:https://rubygems.org/gems/bootsnap/versions/1.16.0

特徴・働き

  • Ruby, Actrive Support, YAMLのメソッド呼び出しの最適化およびキャッシュ
  • Path Pre-Scanning:ファイルパス自体をキャッシュし無駄なシステムコール数を減らす
  • 公式Documentで「Bootsnap導入前後で6秒から3秒と50%削減」とある

参考サイト

https://www.tumblr.com/y-yagi/161406680990/bootsnapについて
https://qiita.com/Daniel_Nakano/items/aadeaa7ae4e227b73878
https://techblog.housmart.co.jp/2017/12/11/ruby-gem-bootsnap/


debug

Ruby用のデバッガ。Rubyプログラムを任意の点で一時停止させデバッグコンソールを利用できる。

# GitHub
This library provides debugging functionality to Ruby (MRI) 2.6 and later.
This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by set_trace_func.

# RubyGems
Debugging functionality for Ruby. This is completely rewritten debug.rb which was contained by the ancient Ruby versions.

GitHub:https://github.com/ruby/debug
RubyGems:https://rubygems.org/gems/debug/versions/1.8.0

特徴・働き

  • byebugbinding.pryのような使い方
  • binding.breakコマンドで任意の箇所にブレークポイントを設ける

参考リンク

https://qiita.com/yuskubo/items/111a87e2402de8e12914#backtrace-bt
https://zenn.dev/igaiga/books/rails-practice-note/viewer/ruby_rails_debug_gem


web-console

View 内でコンソールを立ち上げて、変数や parameter などの状態を見る事の出来るデバック用のgem。

# GitHub
Web Console is a debugging tool for your Ruby on Rails applications.

# RubyGems
A debugging tool for your Ruby on Rails applications.

GitHub:https://github.com/rails/web-console
RubyGems:https://rubygems.org/gems/web-console?locale=ja

特徴・働き

  • View/Controller内の任意の箇所でconsoleメソッドを使用すればコンソールを呼び出せる

参考サイト

https://www.tumblr.com/y-yagi/96428108880/railsのweb-consoleについて
https://qiita.com/pekepek/items/74c8b1f4c886fc9b15cd


error-highlight

バックトレース中の詳細なエラー位置を表示してくれる組み込みの gem

# RubyGems
The gem enhances Exception#message by adding a short explanation where the exception is raised

GitHub:https://github.com/ruby/error_highlight
RubyGems:https://rubygems.org/gems/error_highlight

特徴・働き

  • エラーが発生した行のほかに、その行でエラーが発生した範囲もエラー画面のコード片で精密に表示される
  • 全てのエラーが表示されるわけではなくZeroDivisionErrorなどは位置の表示がされないため注意が必要

参考サイト

https://qiita.com/Satoooon/items/2412e9ba6de1f3afefb1
https://techracho.bpsinc.jp/hachi8833/2022_02_25/115817


capybara

E2Eテスティングフレームワーク。実際にユーザーがWEBアプリケーションを使用している際に、意図した通りの動作をするかテストするためのもの。

# GitHub
Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.

# RubyGems
Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website

GitHub:https://github.com/teamcapybara/capybara
RubyGems:https://rubygems.org/gems/capybara/versions/3.39.2

特徴・働き

  • WEBアプリをブラウザで自動実行できる
  • Headlessブラウザを操作できる(GUI無しのブラウザ)
  • JavaScriptはデフォルトではサポートしていない(seleniumドライバで対応)

参考リンク

https://qiita.com/morrr/items/0e24251c049180218db4
https://qiita.com/koki_73/items/c033e7a059192ec73c25
https://zenn.dev/megeton/articles/f73dc1a0db69b7
http://www.code-magagine.com/?p=9739


selenium-webdriver

Webアプリケーションをテストするためのポータブルフレームワーク。

# GitHub
Selenium is an umbrella project encapsulating a variety of tools and libraries enabling web browser automation. Selenium specifically provides an infrastructure for the W3C WebDriver specification — a platform and language-neutral coding interface compatible with all major web browsers.

# RubyGems
Selenium implements the W3C WebDriver protocol to automate popular browsers. It aims to mimic the behaviour of a real user as it interacts with the application's HTML. It's primarily intended for web application testing, but any web-based task can automated.

GitHub:https://github.com/SeleniumHQ/selenium
RubyGems:https://rubygems.org/gems/selenium-webdriver/versions/4.14.0

特徴・働き

  • 主目的はテストだが、WEBブラウザの操作を自動化できるため毎日特定のWEBページをスクレイピングする、特定の操作を行うなどアプリケーションを自動で実行することができる
  • Capybara + SeleniumでJavaScriptを含めたWEBアプリケーションの動作をブラウザ上でテストできる

参考にしたサイト

https://zenn.dev/usmoo/articles/133bb9ab4864d7
https://magazine.techacademy.jp/magazine/18704

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11