Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
module DataMapper module Is module Accessible def is_accessible include InstanceMethods property :created_id, Integer belongs_to :created_by, :class_name => "User", :child_key => [:created_id] has n, :accessors, :through => Resource, :class_name => "User" attr_accessor :accessor_ids attr_accessor :current_user before :create, :init_accessors before :save, :add_accessors end module InstanceMethods def viewable?(user = nil) return false if accessors.empty? user ||= current_user accessors.include?(user) end def init_accessors unless @current_user.nil? self.created_by = @current_user self.accessors << @current_user end end def add_accessors unless self.accessor_ids.nil? self.accessor_ids.split(',').each{|user_id| accessors << User[user_id]} end end end end end end DataMapper::Resource::ClassMethods.send(:include, DataMapper::Is::Accessible)
This paste will be private.
From the Design Piracy series on my blog: