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
12
8k
どうしてこうなった?から理解するActive Recordの関連の裏側
willnet
5
860
Exceptional Rails
willnet
6
6.8k
Breaking the Flaky Test Cycle
willnet
2
1.9k
mrskで広がるインフラの選択肢
willnet
1
970
アプリケーションを長期にわたって無理なく運用するためのたったひとつの方法
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
10分でわかるfreeeのQA
freee
1
3.4k
エンジニア候補者向け資料2024.11.07.pdf
macloud
0
4.5k
スプリントゴールにチームの状態も設定する背景とその効果 / Team state in sprint goals why and impact
kakehashi
2
120
DatabricksにおけるLLMOpsのベストプラクティス
taka_aki
4
1.3k
ジョブマッチングサービスにおける相互推薦システムの応用事例と課題
hakubishin3
2
520
コンテンツを支える 若手ゲームクリエイターの アートディレクションの事例紹介 / cagamefi-game
cyberagentdevelopers
PRO
1
140
物価高なラスベガスでの過ごし方
zakky
0
470
エムスリー流!難読クイズを作ってPythonの深淵に触れるコツ! - 技育CAMPアカデミア
vaaaaanquish
0
100
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
Vueで Webコンポーネントを作って Reactで使う / 20241030-cloudsign-vuefes_after_night
bengo4com
4
2.5k
TinyGoを使ったVSCode拡張機能実装
askua
2
120
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
250
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
180
21k
How to Ace a Technical Interview
jacobian
275
23k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
680
Navigating Team Friction
lara
183
14k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Building Adaptive Systems
keathley
38
2.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
14
2k
For a Future-Friendly Web
brad_frost
175
9.4k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
A designer walks into a library…
pauljervisheath
202
24k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
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