Sha256: 97043232ee0b4d50fc1435caa0e04d96b1d07d23aa494df3cbd8614a18eff657
Contents?: true
Size: 1.04 KB
Versions: 5
Compression:
Stored size: 1.04 KB
Contents
# encoding: UTF-8 module MongoMapper module Plugins module Associations class SingleAssociation < Base def setup(model) @model = model model.associations_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1) def #{name} get_proxy(associations[#{name.inspect}]).read end def #{name}=(value) get_proxy(associations[#{name.inspect}]).write(value) end def #{name}? get_proxy(associations[#{name.inspect}]).present? end def build_#{name}(attrs={}, &block) get_proxy(associations[#{name.inspect}]).build(attrs, &block) end def create_#{name}(attrs={}, &block) get_proxy(associations[#{name.inspect}]).create(attrs, &block) end def create_#{name}!(attrs={}, &block) get_proxy(associations[#{name.inspect}]).create!(attrs, &block) end end_eval end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems