Sha256: e3266578209047ee1d6013e94b392db077f02a3019fa6d6d15bac57eb91fcbb1
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
= Active Object -- 基于Ruby的对象-key/value映射 Active Object是用来访问LightCloud/TokyoCabinet/TokyoTyrant的工具,实现了持久化数据与对象的映射。 == 主要特性 * 自定义持久化属性. class User < ActiveObject::Base attribute :name,:email end * 建立对象引用,消除冗余. class User < ActiveObject::Base attribute :name,:email has_one :icon #=> 表示每个人有一张肖像 has_many :friends #=> 表示每个人可以有多个朋友 end class Icon < ActiveObject::Base attribute :content end class Friend < ActiveObject::Base attribute :friend_name,:remark,:created_at has_one :user end * 可以对对象应用验证规则,而且对新对象或存在的对象应用不同的验证规则. class User < ActiveObject::Base attribute :name,:email validates_presence_of :name,:email end * 回调. class User < ActiveObject::Base before_destroy do |object| puts object end end * 观察器. class UserObserver < ActiveObject::Observer def after_create(user) puts user end end * 多级继承 class User < ActiveObject::Base;end class Account < User;end == 示例 在Rails中应用Active Object 在环境文件的最后加入下列代码(假设LightCloud配置文件与环境文件在同一个目录下): require 'activeobject' ActiveObject::Base.configure :LC,File.join(File.dirname(__FILE__),'light_cloud.yml') 在项目中使用观察器 在环境文件的最后加入下列代码: ActiveObject::Base.observers = :account_observer ActiveObject::Base.instantiate_observers
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activeobject-0.0.3 | ./README |
activeobject-0.0.4 | ./README |