jsonb_accessor 项目教程
1. 项目的目录结构及介绍
jsonb_accessor/
├── Gemfile
├── Gemfile.lock
├── LICENSE.md
├── README.md
├── jsonb_accessor.gemspec
├── lib/
│ ├── jsonb_accessor/
│ │ ├── version.rb
│ │ └── ...
│ └── jsonb_accessor.rb
├── spec/
│ ├── jsonb_accessor_spec.rb
│ └── ...
└── ...
- Gemfile: 定义了项目所需的依赖。
- Gemfile.lock: 锁定依赖版本。
- LICENSE.md: 项目的许可证。
- README.md: 项目说明文档。
- jsonb_accessor.gemspec: 项目的 gemspec 文件,包含项目信息和依赖。
- lib/: 包含项目的主要代码。
- jsonb_accessor.rb: 项目的主文件。
- jsonb_accessor/: 包含项目的各个模块。
- spec/: 包含项目的测试代码。
2. 项目的启动文件介绍
项目的启动文件是 lib/jsonb_accessor.rb
,它负责加载项目的各个模块并初始化项目。
require "jsonb_accessor/version"
require "active_record"
require "active_support/all"
module JsonbAccessor
# 项目的主要逻辑
end
require "jsonb_accessor/scopes"
require "jsonb_accessor/macro"
require "jsonb_accessor/query_helper"
require "jsonb_accessor/helpers"
require "jsonb_accessor/store_key_helpers"
require "jsonb_accessor/type"
require "jsonb_accessor/field"
require "jsonb_accessor/attribute_helpers"
require "jsonb_accessor/associations"
require "jsonb_accessor/errors"
3. 项目的配置文件介绍
项目的配置文件主要是 jsonb_accessor.gemspec
,它定义了项目的基本信息、依赖和文件列表。
Gem::Specification.new do |spec|
spec.name = "jsonb_accessor"
spec.version = JsonbAccessor::VERSION
spec.authors = ["Your Name"]
spec.email = ["your@email.com"]
spec.summary = "Adds typed jsonb backed fields to your ActiveRecord models."
spec.description = "This gem adds typed jsonb backed fields as first class citizens to your ActiveRecord models."
spec.homepage = "https://github.com/madeintandem/jsonb_accessor"
spec.license = "MIT"
spec.files = Dir["{lib}/**/*", "LICENSE.md", "README.md"]
spec.require_paths = ["lib"]
spec.add_dependency "activerecord", ">= 5.0"
spec.add_dependency "activesupport", ">= 5.0"
spec.add_dependency "pg", ">= 0.18.1"
spec.add_development_dependency "appraisal", "~> 2.2.0"
spec.add_development_dependency "awesome_print", ">= 0"
spec.add_development_dependency "database_cleaner", "~> 1.6.0"
spec.add_development_dependency "pry", ">= 0"
spec.add_development_dependency "pry-doc", ">= 0"
spec.add_development_dependency "pry-nav", ">= 0"
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "rspec", "~> 3.6.0"
spec.add_development_dependency "rubocop", "~> 1"
end
这个文件定义了项目的名称、版本、作者、描述、主页、许可证、文件列表、依赖和开发依赖。