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
9.8k
どうしてこうなった?から理解するActive Recordの関連の裏側
willnet
5
1.2k
Exceptional Rails
willnet
6
7k
Breaking the Flaky Test Cycle
willnet
2
2k
mrskで広がるインフラの選択肢
willnet
1
1k
アプリケーションを長期にわたって無理なく運用するためのたったひとつの方法
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
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
450
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
4k
Server-Side Engineer of LINE Sukimani
lycorp_recruit_jp
0
430
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
39k
AWS re:Invent 2024 recap
hkoketsu
0
500
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
190
AWS re:Invent 2024 ふりかえり勉強会
yhana
0
620
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
200
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
150
10年もののバグを退治した話
n_seki
0
110
ネットワーク可視化の世界
likr
7
5.1k
20241218_今年はSLI/SLOの導入を頑張ってました!
zepprix
0
210
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Optimizing for Happiness
mojombo
376
70k
Making Projects Easy
brettharned
116
6k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Statistics for Hackers
jakevdp
796
220k
Visualization
eitanlees
146
15k
The Cult of Friendly URLs
andyhume
78
6.1k
Unsuck your backbone
ammeep
669
57k
Thoughts on Productivity
jonyablonski
68
4.4k
It's Worth the Effort
3n
183
28k
Facilitating Awesome Meetings
lara
50
6.1k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
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