1. 先要有https://rubygems.org/帳號
2. 安裝環境必要套件
4. 設定檔
voteable_shawn/voteable_shawn.gemspec
voteable_shawn/lib/voteable_shawn.rb
4. 安裝編譯套件
6. Repo:
https://github.com/shawnkaku/voteable_gem.git
7. ##應該改用 bundle gem voteable_shawn
$ bundle gem voteable_shawn
create voteable_shawn/Gemfile
create voteable_shawn/Rakefile
create voteable_shawn/LICENSE.txt
create voteable_shawn/README.md
create voteable_shawn/.gitignore
create voteable_shawn/voteable_shawn.gemspec
create voteable_shawn/lib/voteable_shawn.rb
create voteable_shawn/lib/voteable_shawn/version.rb
8. 打包gem
$ cd voteable_shawn/
$ gem build voteable_shawn.gemspec
WARNING: no homepage specified
WARNING: open-ended dependency on rake (>= 0, development) is not recommended
if rake is semantically versioned, use:
add_development_dependency 'rake', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: voteable_shawn
Version: 0.0.1
File: voteable_shawn-0.0.1.gem
9. 上傳gem
$ gem push voteable_shawn-0.0.1.gem
2. 安裝環境必要套件
$ gem update --system
$ gem install rubygems-update
Fetching: rubygems-update-2.7.6.gem (100%)
Successfully installed rubygems-update-2.7.6
Parsing documentation for rubygems-update-2.7.6
Installing ri documentation for rubygems-update-2.7.6
Done installing documentation for rubygems-update after 28 seconds
1 gem installed
$ update_rubygems
3. 建立gem資料夾 (voteable_shawn)
$mkdir voteable_shawn
$cd voteable_shawn
$mkdir lib
4. 設定檔
voteable_shawn/voteable_shawn.gemspec
Gem::Specification.new do |s|
s.name = 'voteable_shawn'
s.version = '0.0.0'
s.licenses = ['MIT']
s.summary = "This is a voteable gem example!"
s.description = "The voting gem!"
s.authors = ["Shawn"]
s.email = 'shawnkuo67@gmail.com'
s.files = ["lib/voteable_shawn.rb"]
s.homepage = 'https://rubygems.org/gems/example'
s.metadata = { "source_code_uri" => "https://github.com/example/example" }
end
voteable_shawn/lib/voteable_shawn.rb
module Voteable
extend ActiveSupport::Concern
included do
has_many :votes, as: :voteable
end
def vote_total
self.vote_up - self.vote_down
end
def vote_up
self.votes.where(vote: true).size
end
def vote_down
self.votes.where(vote: false).size
end
end
4. 安裝編譯套件
$ gem install gemcutter
Fetching: gemcutter-0.7.1.gem (100%)
********************************************************************************
Thanks for installing Gemcutter! You can now run:
gem push merged into RubyGems 1.3.6
gem owner merged into RubyGems 1.3.6
gem webhook register urls to be pinged when gems are pushed
gem yank remove a specific version of a gem from RubyGemgem.org
********************************************************************************
Successfully installed gemcutter-0.7.1
Parsing documentation for gemcutter-0.7.1
Installing ri documentation for gemcutter-0.7.1
Done installing documentation for gemcutter after 0 seconds
1 gem installed
$ gem list gemcutter
*** LOCAL GEMS ***
gemcutter (0.7.1)
5. 發布gem
$ gem push voteable_shawn-0.0.0.gem
6. Repo:
https://github.com/shawnkaku/voteable_gem.git
7. ##應該改用 bundle gem voteable_shawn
$ bundle gem voteable_shawn
create voteable_shawn/Gemfile
create voteable_shawn/Rakefile
create voteable_shawn/LICENSE.txt
create voteable_shawn/README.md
create voteable_shawn/.gitignore
create voteable_shawn/voteable_shawn.gemspec
create voteable_shawn/lib/voteable_shawn.rb
create voteable_shawn/lib/voteable_shawn/version.rb
8. 打包gem
$ cd voteable_shawn/
$ gem build voteable_shawn.gemspec
WARNING: no homepage specified
WARNING: open-ended dependency on rake (>= 0, development) is not recommended
if rake is semantically versioned, use:
add_development_dependency 'rake', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: voteable_shawn
Version: 0.0.1
File: voteable_shawn-0.0.1.gem
9. 上傳gem
$ gem push voteable_shawn-0.0.1.gem
留言
張貼留言