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.8k
どうしてこうなった?から理解するActive Recordの関連の裏側
willnet
5
940
Exceptional Rails
willnet
6
6.8k
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
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
720
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
170
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
580
TypeScript、上達の瞬間
sadnessojisan
46
13k
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
290
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
960
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Six Lessons from altMBA
skipperchong
27
3.5k
The Invisible Side of Design
smashingmag
298
50k
Faster Mobile Websites
deanohume
305
30k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building an army of robots
kneath
302
43k
Gamification - CAS2011
davidbonilla
80
5k
A designer walks into a library…
pauljervisheath
203
24k
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