ActiveModel 省略了什么
[![Build History][build badge]][build history] ActiveAttr 是一组模块,可让您轻松创建普通的 Ruby 代码。 没有使用 ORM(例如 ActiveRecord)中的功能的模型, 重新发明轮子。将 ActiveAttr 看作是 ActiveModel 所遗漏的内容。 ActiveAttr 以 Ruby gem 的形式分发 [在 rubygems.org][rubygems]。 [![ActiveAttr Railscast][railscast 海报]][railscast]
将 Attributes 模块添加到您的类中,可以为定义属性提供 DSL。 您模型的属性。
class Person
include ActiveAttr::Attributes
attribute :first_name
attribute :last_name
end
person = Person.new
person.first_name = "Chris"
person.last_name = "Griego"
person.attributes #=> {"first_name"=>"Chris", "last_name"=>"Griego"}将 AttributeDefaults 模块添加到您的类中,是对 Attributes 的扩展。 允许使用属性声明默认值。
class Person
include ActiveAttr::AttributeDefaults
attribute :first_name, :default => "John"
attribute :last_name, :default => "Doe"
end
person = Person.new
person.first_name #=> "John"
person.last_name #=> "Doe"将 QueryAttributes 模块添加到您的类中,是对 Attributes 的一种扩展 提供用于查询属性的实例方法。
class Pe
[api]: http://rubydoc.info/gems/active_attr
[contributors]: https://github.com/cgriego/active_attr/contributors
[railscast poster]: http://railscasts.com/static/episodes/stills/326-activeattr.png
[railscast]: http://railscasts.com/episodes/326-activeattr
[rubygems]: http://rubygems.org/gems/active_attr
[protected_attributes]: https://github.com/westonganger/protected_attributes_continued
[strong_parameters]: https://github.com/rails/strong_parameters
[speakerdeck]: https://speakerdeck.com/u/cgriego/p/models-models-every-where
[build badge]: https://github.com/cgriego/active_attr/actions/workflows/test.yaml/badge.svg
[build history]: https://github.com/cgriego/active_attr/actions/workflows/test.yaml暂无开放 Issues,或尚未同步最近议题。