1 新建一个gem:
> bundle gem my_mongoid
create my_mongoid/Gemfile
create my_mongoid/Rakefile
create my_mongoid/LICENSE.txt
create my_mongoid/README.md
create my_mongoid/.gitignore
create my_mongoid/my_mongoid.gemspec
create my_mongoid/lib/my_mongoid.rb
create my_mongoid/lib/my_mongoid/version.rb
新建gem所依赖的gem文件放在my_mongoid.gemspec文件里.
这个gem版本号以字符串常量的形式放在lib/my_mongoid/version.rb里.
module MyMonoid
VERSION = "0.2.1"
end
2 使用rake管理Gem:
> rake -T
rake build # Build my_monoid-0.2.1.gem into the pkg directory
rake install # Build and install my_monoid-0.2.1.gem into system gems
rake release # Create tag v0.2.1 and build and push my_monoid-0.2.1.gem to...
3 使用rake build构建gem:
> rake build
rake aborted!
ERROR: While executing gem ... (Gem::InvalidSpecificationException)
"FIXME" or "TODO" is not a description
Tasks: TOP => build
(See full trace by running task with --trace)
需要把my_monoidmy_monoid.gemspec里的
spec.description = %q{TODO: Write a gem description}
spec.summary = %q{TODO: Write a gem summary}
改为
spec.description = %q{Write a gem description}
spec.summary = %q{Write a gem summary}
此时可以build成功:
> rake build
my_monoid 0.2.1 built to pkg/my_monoid-0.2.1.gem.
4 安装gem:
> gem install pkg/my_monoid-0.2.1.gem --local
Successfully installed my_monoid-0.2.1
Parsing documentation for my_monoid-0.2.1
Installing ri documentation for my_monoid-0.2.1
Done installing documentation for my_monoid after 1 seconds
1 gem installed
5 查看安装路径:
> gem which my_monoid
D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/my_monoid-0.2.1/lib/my_mono
id.rb