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
RubyGems入門
Search
Shinichi Maeshima
December 10, 2018
Technology
2
3.9k
RubyGems入門
リンカーズさんの社内LT会で発表した内容です。RubyGemsの仕組みと作り方について。
Shinichi Maeshima
December 10, 2018
Tweet
Share
More Decks by Shinichi Maeshima
See All by Shinichi Maeshima
Sidekiq vs Solid Queue
willnet
13
8.9k
どうしてこうなった?から理解するActive Recordの関連の裏側
willnet
5
950
Exceptional Rails
willnet
6
6.9k
Breaking the Flaky Test Cycle
willnet
2
2k
mrskで広がるインフラの選択肢
willnet
1
980
アプリケーションを長期にわたって無理なく運用するためのたったひとつの方法
willnet
2
2.1k
HotwireからDHHが考えるこれからのRailsとJSの付き合い方を知る
willnet
14
13k
Rails6.1で新しく入る機能について
willnet
12
15k
Concerns about Concerns
willnet
11
34k
Other Decks in Technology
See All in Technology
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
200
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
Terraform Stacks入門 #HashiTalks
msato
0
370
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
7
720
【平成レトロ】へぇボタンハック👨🔧
vanchan2625
0
110
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
670
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
160
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
1
220
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
730
組織成長を加速させるオンボーディングの取り組み
sudoakiy
3
280
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
590
AI前提のサービス運用ってなんだろう?
ryuichi1208
8
1.4k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
The Cult of Friendly URLs
andyhume
78
6k
A Tale of Four Properties
chriscoyier
156
23k
Six Lessons from altMBA
skipperchong
27
3.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Language of Interfaces
destraynor
154
24k
GraphQLとの向き合い方2022年版
quramy
43
13k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
A better future with KSS
kneath
238
17k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Transcript
rubygemsೖ
ΈΜͳgem͖Ͱ͢ΑͶ??
gemΛ͏ਓଟ͍͚Ͳ࡞Δਓগͳ͍
gem࡞ΔͷͬͯࢥͬͨΑΓ ؆୯ ͳΜͰ͢Αͱ͍͏Λ͠·͢
࡞Δલʹɺ·ͣ Έʹ͍ͭͯͬ͘͟Γ ղઆ͠·͢
ͦͦgemͬͯͲ͏͍͏Ͱ ಈ͍͍ͯΔͷ https://github.com/rubygems/rubygems » ΈΜͳ͓ͳ͡Έgem installͳͲͷίϚϯυ » gemͷrequireͷڍಈΛఏڙ͍ͯ͠Δ
rubygemsΛrequire͢Δͱɺ require͕ஔ͖ΘΔ 1.·ͣී௨ʹrequire($LOAD_PATHΛ୳͢) 2.ͳʹݟ͔ͭΒͳ͔ͬͨΒɺաڈʹgem installͨ͠gemΛ୳͠ ͯɺݟ͔ͭͬͨΒ$LOAD_PATHʹͦͷgemͷpathΛՃͯ͠ require͢Δ
rubygemsࣗಈͰrequire͞ΕΔ » Ruby1.9͔Β » ࣗಈͰrequireͨ͘͠ͳ͍ͱ͖RubyͷϏϧυ࣌ʹexport RUBYOPT='--disable gems'͓ͯ͘͠ඞཁ͕͋ΔΒ͍͠
ͰͨͪΏΔ;Θ Rails͍ͬͯ΄ͱ ΜͲgemΛrequire͠ ͳ͍ΑͶʁ
Bundler
Gemfile ྫ gem ‘rails’, ‘>~ 5.2.0’ gem 'bootsnap', '>= 1.1.0',
require: false
Bundler.setup && Bundler.require ͜ΕΒRailsڥΛϩʔυ͢Δͱ͖ʹඞ࣮ͣߦ͞ΕΔ # config/boot.rb require 'bundler/setup' # config/application.rb
Bundler.require(*Rails.groups)
Bundler.setup Gemfileʹఆٛ͞Ε͍ͯΔgemΛͥΜͿ$LOAD_PATHʹՃ͢Δ
Bundler.require(*Rails.groups) Gemfileʹఆٛ͞Ε͍ͯΔgemΛrequire͢Δɻͨͩ͠ » Ҿͷgroupʹଐ͍ͯ͠ͳ͍gemrequire͠ͳ͍ » gem 'bootsnap', '>= 1.1.0', require:
falseΈ͍ͨʹ require: falseͱͳ͍ͬͯΔgemrequire͠ͳ͍ » ։ൃ༻ͱ͔ςετ༻ͷgemͩͱҰ୴require: falseͱ͓͍ͯ͠ ͯɺಛఆͷίϚϯυͷͱ͖͚ͩ໌ࣔతʹrequire͢Δɺͱ͍͏gem ͕࣌ʑ͋Γ·͢
࣍ʹ࡞Γํ
budler͕gemͷ࡞Γ༻ͷίϚ ϯυΛఏڙ͍ͯ͠Δ bundle gem gemͷ໊લ ͰOK
ࢼ͠ʹhelloworld gemΛ࡞ͬͯΈ ·͢ bundle gem helloworld Creating gem 'helloworld'... MIT
License enabled in config Code of conduct enabled in config create helloworld/Gemfile create helloworld/lib/helloworld.rb create helloworld/lib/helloworld/version.rb create helloworld/helloworld.gemspec create helloworld/Rakefile create helloworld/README.md create helloworld/bin/console create helloworld/bin/setup create helloworld/.gitignore create helloworld/.travis.yml create helloworld/.rspec create helloworld/spec/spec_helper.rb create helloworld/spec/helloworld_spec.rb create helloworld/LICENSE.txt create helloworld/CODE_OF_CONDUCT.md Initializing git repo in /Users/shinichi.maeshima/tmp/helloworld Gem 'helloworld' was successfully created. For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html
ͨ͘͞ΜϑΝΠϧ͕ੜ͞Εͨ . !"" CODE_OF_CONDUCT.md !"" Gemfile !"" LICENSE.txt !"" README.md
!"" Rakefile !"" bin # !"" console # $"" setup !"" helloworld.gemspec !"" lib # !"" helloworld # # $"" version.rb # $"" helloworld.rb $"" spec !"" helloworld_spec.rb $"" spec_helper.rb
͓͖͑ͯ͘͜ͷ̎ͭ » lib/helloworld.rb » gemΛrequireͨ͠ͱ͖ͷىʹͳΔϑΝΠϧ » helloworld.gemspec » gemͷઆ໌ґଘؔΛఆٛ͢ΔϑΝΠϧ
lib/helloworld.rb ྫ require "helloworld/version" module Helloworld def self.say puts 'hello
world!' end end
helloworld.gemspec ྫɻҰ෦লུͯ͠·͢ Gem::Specification.new do |spec| spec.name = "helloworld" spec.version =
Helloworld::VERSION spec.authors = ["willnet"] spec.email = ["
[email protected]
"] spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.} spec.description = %q{TODO: Write a longer description or delete this line.} spec.homepage = "TODO: Put your gem's website or public repo URL here." spec.license = "MIT" spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.17" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" end
TODO: ͱͳ͍ͬͯΔͱ͜ΖΛॻ͍ͯͳ͍ͱౖ ΒΕΔͷͰͪΌΜͱॻ͖·͠ΐ͏ ྫͷsummaryͱdescriptionͱhomepageΛमਖ਼ Gem::Specification.new do |spec| spec.name = "helloworld"
spec.version = Helloworld::VERSION spec.authors = ["willnet"] spec.email = ["
[email protected]
"] spec.summary = %q{Hello World} spec.description = %q{Hello World gem for sample} spec.homepage = “https://github.com/willnet/helloworld” spec.license = "MIT" spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.17" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" end
ґଘ͍ͯ͠Δgem͕͋Δͱ͖ helloworld.gemspecʹॻ͖ ·͢ ྫ spec.add_dependency ‘rails’ spec.add_development_dependency ‘gimei’
ϩʔΧϧڥʹΠϯετʔϧ͠ ͯಈ࡞Λࢼ͍ͨ͠ rake install require 'helloworld' #=> true Helloworld.say #=>
nil hello world!
ςετͷৄࡉͳॻ͖ํলུ͠ ·͢ ςετ༻ͷσΟϨΫτϦ͕ੜ͞Ε͍ͯΔͷͰɺ͙͢ʹ͍ͭͷΑ͏ʹॻ ͚·͢
ςετॻ͖·͠ΐ͏ Ͷ ❤
gem͕ͨ͠
rubygems.orgʹϦϦʔε͢Δ ͧʂ ࣄલʹrubygems.orgͰΞΧϯτ࡞͓ͬͯ͘ඞཁ͋Δͣ rake release
ࣾͰ͔͠Θͳ͍gemͬͯͲ͏ ϗεςΟϯά͢Δͷʁ » githubgitlabʹίʔυΛϗεςΟϯά » Gemfileʹ࣍ͷΑ͏ʹॻ͍͓͚ͯOK gem ‘helloworld’, git: ‘https://github.com/willnet/helloworld.git'
gemʹΓग़ͤͦ͏ ͳίʔυɺͲΜͲΜ Γग़͍͖ͯ͠·͠ ΐ͏!!!1