ãã®èšäºã¯ããµãâãç¥æ§ã«æ§ããŠãäžéè©Šéšã»PFäœæãæŸãæããŠgemäœæã«å€ããã æ¥èšã§ãïŒ
gemã®å 容ã¯ããšã£ãŠãç°¡åã§ãã®ã§GitHubã«é£ãã§å 容ãèŠãŠè¡ã£ãŠäžãããäžã€ã®gemã®å 容ããããããã«ãªããšãä»ã®ãã®ã«ãå¿çšãã§ããgemã䜿ãéã®æå©ããšãªã£ãŠããããšä¿¡ããŠããŸãïŒ
泚æïŒééãçãããããããŸããïŒïŒïŒæ°ä»ãããŸãããããææ°ã§ããæããŠäžããðŸ
ç®æ¬¡ã ã«ãðŸ
- ãããäœããŸããïŒ
- ã»ãŒããããåèã«äœããŸããðŸ
- ç§ã®ç°å¢
- äºåæºå
- gemäœæã®å€§ãŸããªæµã
- ïŒãRubyGemsã§ãäœãããgemãšåãååããªãã調ã¹ãŸãããïŒ
- ïŒãGemã®ç®±ïŒé圢ïŒãäœããŸãã
- ïŒãèªåã®æããŸãŸã«äžèº«ãäœã£ãŠãããŸãããïŒ
- ïŒãåäœç¢ºèªãããŠãããŸãããïŒ
- ïŒãRSpecãæžããŠãã¡ãããšç¢ºèªããŠãããŸãããïŒ
- ïŒãäžã«åºããŠãããŸãããïŒ
-ãäžèšä»¥å€ã®åèæç®
-ãå ¬åŒããåããïŒ
-ãæåŸã«
ãããäœããŸããðŸ
æåãå ¥ãããšããã®æ°ã ããðŸããåºãŠããgemã§ãã
ã»ãŒããããåèã«äœããŸããðŸ
ç§ã®ç°å¢ðŸ
ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin21]
bundle -v
Bundler version 2.2.22
äºåæºåðŸ
- Githubã«ä»åäœãgemã®ãœãŒã¹ã³ãŒãã眮ãããã®æ°ãããªããžããªãäœæ
- RubyGems
- ã¢ã«ãŠã³ãç»é²
- API keysã®äœæïŒè©³ããããšã§æžãïŒ
- ä»æ§ãå€ãã£ãŠããªãã調ã¹ã
- Bundler
- ⢠bundle -v ãããŠBundler version 1.9.0æªæºã®å Žåãgem update bundlerããŠãã ããã
ðŸgemäœæã®å€§ãŸããªæµãðŸ
ïŒãgemã®ååã¯ãuniqueïŒäžæïŒã§ãªããã°ãªããŸãããRubyGemsã§ãäœãããgemãšåãååããªãã調ã¹ãŸãããïŒ
ïŒãç®±ïŒé圢ïŒãäœããŸãã
gemã¯çŽ æŽãããããšã«ç®±ïŒé圢ïŒãçšæããŠãããŸãããããäžæãã€ã³ã¹ããŒã«ã§ããããããšã¯ç©ŽåãåŒã«èªåããããããšãå
¥ããŠããã ãã»ã»ã»
ãTODOïŒãæ¹åŒã§ãæžããŠããã®ãåããããããŠããã£ãã§ããå
šéšåãããšã¡ãããšgemã«ãªã£ãŠãã®ã§äžæè°ã§ããïŒ
ïŒãèªåã®æããŸãŸã«äžèº«ãäœã£ãŠãããŸãããïŒ
PFãšäžç·ã§ãäžæŠåœ¢ã«ããŠæ¬¡ã«è¡ãæ¹ããããšæããŸãïŒ
PFãããããã¶ããå®è£
ã«ãããã³ã¹ããäœãã®ã§ã©ãã©ãäžèº«ãç¹æ€ã»ä¿®æ£ã»æ¹åããŠè¡ã£ãæ¹ãé¢çœãããªã£ãŠæããŸãïŒ
ïŒãåäœç¢ºèªãããŠãããŸãããïŒãŸãã¯ãgemãšããŠèªèãããŠãããŠããirbãã«ãŠåãããŠãããŸãããïŒ
ïŒãRSpecãæžããŠãã¡ãããšç¢ºèªããŠãããŸãããïŒ
PFã§ã®ãã¹ãã®ç·Žç¿ã«ããªããŸãããããã£ãŠç°¡åã§ããæžããŠã¿ãŸãããïŒ
ïŒãäžã«åºããŠãããŸãããïŒ
ïŒäžã«åºãéã®ããæ¹ãæè¿å€ãã£ãããã§ãäžèšã«åç
§ããŠããèšäºã䜿ããªããªã£ãŠããŸããïŒããããæã¯ãå
¬åŒããæ£çŸ©ã§ãïŒã¡ãããšå
¬åŒãèªã¿ãŸãããïŒæãïŒïŒ
ïŒãRubyGemsã§ãäœãããgemãšåãååããªãã調ã¹ãŸãããðŸ
äžèšã®URLã«ãŠããRubyGemsãã«é£ãã§ãäœãããã¢ããªã®ååãå
¥ããŠã¿ãŸãããïŒ
æ€çŽ¢ã«åŒã£æãããªããã°ããªãã®ã§ãã®ãŸãŸäœã£ãŠãããŸãããïŒ
ããã²ã£ããã£ãŠããŸã£ãå ŽåãäœããŸããã®ã§ååãæ€èšããŸãããã»ã»ã»
ïŒãGemã®ç®±ïŒé圢ïŒãäœããŸãðŸ
ïŒãã¡ãã«é¢ããŠã®èªåã®ããŒã¿ããªãã£ãã®ã§ãã¡ãã®URLãåŒçšããŸãïŒ
Gemã®ããŒã¹ãäœæãã
Bundlerã䜿ã£ãŠäœæããŸããBundlerç¡ãã§ãGemã®äœæã¯ã§ããŸãããçŸåšã¯Bundlerã䜿ãã®ãã¹ã¿ã³ããŒãã®ãããªé°å²æ°ããããŸãã
bundle gem gem_name
ã§ç°¡åã«Gemã®ããŒã¹ãäœæã§ããŸãã
$ bundle gem (you_gem_name)
bundle gem
ã³ãã³ããåããŠäœ¿ãå Žåã¯ããã¹ããRSpecãšminitestã©ã¡ãã§æžãããCODE_OF_CONDUCT.mdãšLICENSE.txtãäœã£ãŠãããã確èªãããŸãã
ããã¹ããRSpecãšminitestã©ã¡ãã§æžãããã¯æ £ããŠããæ¹ãéžæããã°è¯ããšæããŸããç§ã¯RSpecãéžæããŠããŸãããCODE_OF_CONDUCT.mdãšLICENSE.txtãäœã£ãŠããããã¯YESã§è¯ããšæããŸãã
CODE_OF_CONDUCT.md
- gemãžã®ãã¹ãŠã®è²¢ç®è ãåŸãããšãæåŸ ããè¡åèŠç¯ãæäŸããŸãã
LICENSE.txt
- MITã©ã€ã»ã³ã¹ãå«ãŸããŠããŸãã
$ cd (you_gem_name)
$ tree
.
âââ CODE_OF_CONDUCT.md
âââ Gemfile
âââ Gemfile.lock
âââ LICENSE.txt
âââ README.md
âââ Rakefile
âââ bin
â âââ console
â âââ setup
âââ (you_gem_name).gemspec
âââ lib
â âââ (you_gem_name)
â â âââ version.rb
â âââ (you_gem_name).rb
âââ spec
âââ (you_gem_name)_spec.rb
âââ spec_helper.rb
gem_name.gemspecã«ã¯ã¡ã¿ããŒã¿ãå®çŸ©ãããŠããŸããæžãçŽãã¹ããšããã¯ãTODOãšæžãããŠããã®ã§ããããä¿®æ£ããŠãããŸããä¿®æ£ããªããš
bundle install
ããããšãã«æãããŸãã
ïŒãTODOïŒããšãæžããŠããã®ã§æžããšãããè¿·ããæžããŸãïŒïŒ
(you_gem_name).gemspec
# Gemã®èŠçŽãæžããŸã
spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
# Gemã®èª¬æãæžããŸã
spec.description = %q{TODO: Write a longer description or delete this line.}
# ããŒã ããŒãžURL or Githubã®ãªããžããªURLãæžããŸãã
spec.homepage = "TODO: Put your gem's website or public repo URL here."
# https://rubygems.orgãæžããŸã
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
# Githubã®ãªããžããªURLãæžããŸãã
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
# CHANGELOG.mdã®URLãæžããŸãã
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
ïŒèª¬æãè±èªã§ããæžããŠããã®ã§ãèš³ããªããåããŠãã£ãŠãã ããðŸïŒ
ãã®ãã¡ã€ã«ã®äžéšã«ãã次ã®ã³ãŒãã¯ãäŸåããŠããGemãæžãããŠããŸãã
ããã¯Gemfileããèªã¿èŸŒãŸããŠããŸãã®ã§ãGemãè¿œå ããå Žåã¯ããã«è¿œèšããŠããŸãã
(you_gem_name).gemspec
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
ä¿®æ£ãçµãã£ãããäŸågemãã€ã³ã¹ããŒã«ããŸãã
bundle install
ïŒãèªåã®æããŸãŸã«äžèº«ãäœã£ãŠãããŸãããðŸ
ïŒããããã¯ãç§ã®ã³ãŒããäŸã«æããŠãããŸããæ··ãã£ãŠåããã«ããå Žåã¯æããŠãã ããã»ã»ã»çŽããŸãïŒ
libãã£ã¬ã¯ããªã«ã³ãŒããæžããŠãããŸãããïŒ
touch lib/(you_gem_name)/format_(you_gem_name).rb
format_(you_gem_name).rb
class String
#Stringã¯ã©ã¹ã«ãto_padãã¡ãŸãããå¢ãããŠããŸãããšã£ãŠãåçŽã»ã»ã»ãã£ãšé¢çœããã€ã«ã¢ããããŒãããŠããäºå®ã§ãã
def to_pad
word_count = self.size
pad_count = "\u{1F43E}" * word_count.to_i
end
end
(ããã¯èŠæ¬ã§ãïŒå¥œããªããã«å®çŸ©ããŠãããŸãããðŸ)
次ã«(you_gem_name)/format_(you_gem_name).rbãèªã¿èŸŒããããã«requireããŸãïŒ
# frozen_string_literal: true
require_relative "pad_character/version"
require "pad_character/format_pad_character"
module PadCharacter
class Error < StandardError; end
# Your code goes here...
end
ïŒãåäœç¢ºèªãããŠãããŸãããðŸ
äœã£ãã¡ãœããïŒå®çŸ©ïŒãgemã«ããŠåäœç¢ºèªãããŠãããŸãïŒ
rake build
ã³ãã³ãã§pkgãã£ã¬ã¯ããªã«gemãbuildããŸããbuildãå®äºãããgem installãããŸãã
pad_character 0.1.0 built to pkg/pad_character-0.1.0.gem.
% gem install pkg/pad_character-0.1.0.gem
Successfully installed pad_character-0.1.0
Parsing documentation for pad_character-0.1.0
Done installing documentation for pad_character after 0 seconds
1 gem installed
ãã¡ãã®ã³ãã³ãã¯ãgemã®ãã£ã¬ã¯ããªã«å€æŽããå ŽåéœåºŠè¡ã£ãŠgemã«ããŠãã ããã確èªãŸã§ããæ¹ãããã§ãã
installãã§ãããã
% bin/consoleïŒirbã§ãããïŒïŒïŒïŒ
ãèµ·åããŠã確èªããŠãããŸãããïŒ
=> true
irb(main):002:0> "ã¢ã€ãŠãšãª".to_pad
=> "ðŸðŸðŸðŸðŸ"
ãšã£ãŠãããããã«ããã ãæåãåºæ¥ãŸããðŸ
ïŒãRSpecãæžããŠãã¡ãããšç¢ºèªããŠãããŸãããðŸ
ãã¹ããæžããŠãã
ã³ãŒãã®å質ãæ ä¿ããããã«ãã¹ããæžããŸããããGemãšããŠå ¬éãããªãããªãããéèŠã§ããã
ä»åãã¹ãã¯RSpecã䜿ããŸãã
gemã®ãã¹ãã¯ç°¡åã«æžãã»ç°¡åã«ç¢ºèªãåãããããããç·Žç¿ã«ãªããšæããŸãããã²æžããŠã¿ãŸãããïŒããããRSpecã§æžããŠããããšãå€ãããä»ã®gemã®RSpecãèŠãã ãã§ãçµæ§å匷ã«ãªããŸããã©ãã«ã©ããªæãã«æžããŠããããèŠãŠãã£ãŠãã ããã
spec/pad_character_spec.rb
# frozen_string_literal: true
RSpec.describe PadCharacter do
it "å
¥åããæåãå
šãŠðŸã«ãªã" do
str = "ããããã"
expect(str.to_pad).to eql("ðŸðŸðŸðŸðŸ")
end
end
æžãããããã¹ããå®è¡ããŠã¿ãŸãããðŸ
% bundle exec rspec
PadCharacter
å
¥åããæåãå
šãŠðŸã«ãªã
Finished in 0.00222 seconds (files took 0.14626 seconds to load)
1 example, 0 failures
ãã¹ãããéããŸããðŸ
ïŒãäžã«åºããŠãããŸãããðŸ
äžèšã®URLã«åŸã£ãŠãã¢ããããŒãããããšãããã»ã»ã»åºæ¥ãŸããã§ããã»ã»ã»ïŒæ³£ïŒ
% rake release
pad_character 0.1.0 built to pkg/pad_character-0.1.0.gem.
Tag v0.1.0 has already been created.
Enter your RubyGems.org credentials.
Don't have an account yet? Create one at https://rubygems.org/sign_up
Email: azisai07@gmail.com
Password:
Signed in with API key: kashiwagireinanoMacBook-Air.local-kashiwagirena-20230228145755.
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::ConfigFile::FileUtils
Did you mean? FileTest
errorãåºãŠããŸã£ãŠããŸãã»ã»ã»ãªãïŒïŒïŒ
調ã¹ããšãããæè¿RubyGemsã®äœ¿çšãå€ãã£ãããã§ãã
RubyGemsã«ã¢ã«ãŠã³ããäœããŸãã
ãã®åŸã«ãäžèšå
¬åŒãåèã«ãAPI keysããäœã£ãŠãã ãããã¡ã¢ãã»ãã¹ã¯ãŒãã»APIãå¿
èŠãšãããŸã
å®è¡ãããšãgem signinRubyGems.org ã®è³æ Œæ å ±ãããŒåãããã³ããŒãæå¹ã«ããã¹ã³ãŒãã®å ¥åãæ±ããããŸãããã¹ãŠã®ã¹ã³ãŒãã®ããã©ã«ãã®éžæã¯ãããããæå¹ã«ããããšã§ã¯ãããŸããã
ã«ãŒããã£ã¬ã¯ããªã«ç§»ååŸãäžèšã³ãã³ããå®è¡ããŠãæ
å ±ãå
¥ããŸãã
[ y/n ]ã§èããããã®ã¯äžèšãšäžç·ã«ããŠãã ãã
å
¬åŒã«ãåããã®ãæžããŠãããŸã
MacBook-Air ~% gem signin
Enter your RubyGems.org credentials.
Don't have an account yet? Create one at https://rubygems.org/sign_up
Email: azisai07@gmail.com
Password:
API Key name [kashiwagireinanoMacBook-Air.local-kashiwagirena-20230228155124]: rubygems_b31fdfb853aa61837bc4f5184d314926c238025d2fa4806f
Please select scopes you want to enable for the API key (y/n)
index_rubygems [y/N]: n
push_rubygem [y/N]: y
yank_rubygem [y/N]: n
add_owner [y/N]: n
remove_owner [y/N]: n
access_webhooks [y/N]: n
show_dashboard [y/N]: n
Signed in with API key: ãã¯ã¯ããããïŒ
https://guides.rubygems.org/make-your-own-gem/#:~:text=OTP (if enabled)ãâå ¬åŒ
MacBook-Air PF % cd pad_character
gemã®ãã£ã¬ã¯ããªã«ç§»ååŸãäžèšã®ã³ãã³ãã«ãŠpushããŸãïŒ
MacBook-Air pad_character % rake build
pad_character 0.1.0 built to pkg/pad_character-0.1.0.gem.
MacBook-Air pad_character % gem push pkg/pad_character-0.1.0.gem
Pushing gem to https://rubygems.org...
Successfully registered gem: pad_character (0.1.0)
äžèšã³ãã³ãã§ãäžã«åºãããšãã§ããŸãïŒ
MacBook-Air pad_character % gem list -r pad_character
*** REMOTE GEMS ***
pad_character (0.1.0)
ãç²ãæ§ã§ãðŸ
ããã«ãŠãgemãäœæããããšãã§ããŸããïŒ
æåŸã«ðââ¬
ç§ã¯æè¡ã«é¢ããŠãèŠææèãç解ãè¿œããªãéšåå€ãããšããªããªãè±èªãæžããŠããã ãã§é ãããŠããŸãæ¹ã®äººã§ããå šã匷ãããªããã°ãäžéè©Šéšã«ïŒã¶æããããããŸããw
ããã§ããããã°ã©ãã³ã°ã楜ããããšããšã«æ°ãã€ããç§ãªãã®åãåãæ¹ãã§ããŠãããšæããŸãã
ãªã®ã§ãããããã®ãŸãŸãåæ¥ã§ããªãã£ããã©ãããããããã«ã«ãã¥ã©ã ãèŸãããšæã£ãŠããæ¹ã倧äžå€«ã§ãïŒã³ãã¥ããã£ã§è©±ããŠã¿ãŠãã ããããã£ãšãã¿ããªåãæ©ã¿ããã話ãèããŠãããã¯ãã»ã»ã»
ãããŠãããªããªãã®äœããããã®ãªã©æ¢ããŠã¿ãŠã¯ã©ãã§ããããïŒ
æè¡ããããã§ãäœãããã®ã¯ãã£ãšãããŸãïŒãããŠãããã¯ããªãã«èªä¿¡ãã€ããŠãããŸãïŒ
ããŠã³ããŒãæ°ãäžæ¥ã§çµæ§ããŠããŠãã³ã·ã§ã³ããããã®ç§ãã
äžèšä»¥å€ã®åèæç®
ãruby çµµæå ãŠãã³ãŒããã§æ€çŽ¢ãããŸããã
å ¬åŒããåããïŒ