SafeFinder:当NullObject遇到ActiveRecord时

时间:2021-05-04 23:49:12
【文件属性】:
文件名称:SafeFinder:当NullObject遇到ActiveRecord时
文件大小:12KB
文件格式:ZIP
更新时间:2021-05-04 23:49:12
Ruby 安全查找器 使用SafeFinder,您可以通过简单的DSL定义模型的Null Object ,并在找不到该模型的实例时将其返回。 安装 将此行添加到您的应用程序的Gemfile : gem 'safe_finder' 然后执行: $ bundle 或将其自己安装为: $ gem install safe_finder 用法 基本的 假设您有一个Post类,并且它具有title和content列。 首先,您需要在模型中包括SafeFinder : class Post < ActiveRecord :: Base include SafeFinder end 现在,您可以像这样查询,如果找不到任何内容,它将返回一个Null Object : # It returns a Null Object null_object = Post . safely . find_by_
【文件预览】:
SafeFinder-master
----.gitignore(93B)
----safe_finder.gemspec(2KB)
----.rspec(31B)
----bin()
--------setup(115B)
--------console(336B)
----.travis.yml(200B)
----spec()
--------null_object_generator_spec.rb(1KB)
--------safe_finder_spec.rb(932B)
--------support()
--------class_wrapper_spec.rb(1KB)
--------generators()
--------spec_helper.rb(513B)
----README.md(3KB)
----lib()
--------safe_finder.rb(878B)
--------safe_finder()
----Gemfile(182B)
----Rakefile(117B)

网友评论