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
Fearsome File Formats
ange
0
390
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
3
1.5k
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
410
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
150
最近のSfM手法まとめ - COLMAP / GLOMAPを中心に -
kwchrk
8
1.5k
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
140
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
200
ISUCON、今年も参加してみた / ISUCON, I challenged it again this year.
dero1to
0
110
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
350
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
28
24k
AI×医用画像の現状と可能性_2024年版/AI×medical_imaging_in_japan_2024
tdys13
0
430
AWS re:Invent 2024 Recap in ZOZO - Serverless で好きなものをしゃべってみた
chongmyungpark
0
460
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
920
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
190
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
180
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
470
Why Our Code Smells
bkeepers
PRO
335
57k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Optimizing for Happiness
mojombo
376
70k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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