OpenURI Redirections 项目教程
1. 项目的目录结构及介绍
open-uri-redirections/
├── lib/
│ ├── open_uri_redirections.rb
│ └── open_uri_redirections/
│ └── patch.rb
├── spec/
│ ├── open_uri_redirections_spec.rb
│ └── spec_helper.rb
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── open_uri_redirections.gemspec
└── .gitignore
- lib/: 包含项目的主要代码文件。
open_uri_redirections.rb
: 主文件,包含对 OpenURI 的扩展。open_uri_redirections/patch.rb
: 具体的补丁代码。
- spec/: 包含项目的测试文件。
open_uri_redirections_spec.rb
: 针对open_uri_redirections
的测试文件。spec_helper.rb
: 测试辅助文件。
- Gemfile: 定义项目的依赖。
- LICENSE.txt: 项目的许可证文件。
- README.md: 项目的说明文档。
- Rakefile: 用于定义任务的文件。
- open_uri_redirections.gemspec: 项目的 gemspec 文件,包含项目的详细信息和依赖。
- .gitignore: 定义 Git 忽略的文件和目录。
2. 项目的启动文件介绍
项目的启动文件是 lib/open_uri_redirections.rb
。这个文件负责加载项目的核心功能,并应用对 OpenURI 的补丁。
# lib/open_uri_redirections.rb
require 'open_uri_redirections/patch'
3. 项目的配置文件介绍
项目的配置文件主要是 open_uri_redirections.gemspec
。这个文件定义了项目的名称、版本、作者、依赖等信息。
# open_uri_redirections.gemspec
Gem::Specification.new do |spec|
spec.name = "open_uri_redirections"
spec.version = "0.2.1"
spec.authors = ["Jaime Iniesta", "Gabriel Cebrian", "Felix C. Stegerman"]
spec.summary = "OpenURI patch to allow redirections between HTTP and HTTPS"
spec.description = "This gem applies a patch to OpenURI to optionally allow redirections from HTTP to HTTPS or from HTTPS to HTTP."
spec.homepage = "https://github.com/open-uri-redirections/open_uri_redirections"
spec.license = "MIT"
spec.files = Dir["lib/**/*", "LICENSE.txt", "README.md", "Rakefile", "open_uri_redirections.gemspec"]
spec.require_paths = ["lib"]
spec.add_development_dependency "fakeweb", "~> 1.3.0"
spec.add_development_dependency "rake", "~> 10.3.2"
spec.add_development_dependency "rspec", "~> 3.1.0"
end
这个文件中包含了项目的详细信息,如名称、版本、作者、描述、主页、许可证等,以及开发依赖。