Sha256: 3a31a03e56053c681a6131e3ca4de47f3d630dba4a836e1ebae98523c7a15920

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

module Cms
  module Behaviors
    module Userstamping
      def self.included(model_class)
        model_class.extend(MacroMethods)
      end
      module MacroMethods      
        def userstamped?
          !!@is_userstamped
        end
        def is_userstamped(options={})
          @is_userstamped = true
          extend ClassMethods
          include InstanceMethods
        
          belongs_to :created_by, :class_name => "Cms::User"
          belongs_to :updated_by, :class_name => "Cms::User"
        
          before_save :set_userstamps
        
          scope :created_by, lambda{|user| {:conditions => {:created_by => user}}}
          scope :updated_by, lambda{|user| {:conditions => {:updated_by => user}}}        
        end
      end
      module ClassMethods
      end
      module InstanceMethods
        def set_userstamps
          current_user = Cms::User.current ? Cms::User.current : nil
          if new_record?
            self.created_by = current_user
          end
          self.updated_by = current_user

        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
browsercms-4.0.0.rc1 lib/cms/behaviors/userstamping.rb
browsercms-4.0.0.beta lib/cms/behaviors/userstamping.rb
browsercms-4.0.0.alpha lib/cms/behaviors/userstamping.rb
browsercms-3.5.7 lib/cms/behaviors/userstamping.rb
browsercms-3.5.6 lib/cms/behaviors/userstamping.rb
browsercms-3.5.5 lib/cms/behaviors/userstamping.rb
browsercms-3.5.4 lib/cms/behaviors/userstamping.rb
browsercms-3.5.3 lib/cms/behaviors/userstamping.rb
browsercms-3.5.2 lib/cms/behaviors/userstamping.rb
browsercms-3.5.1 lib/cms/behaviors/userstamping.rb
browsercms-3.5.0 lib/cms/behaviors/userstamping.rb
browsercms-3.5.0.rc3 lib/cms/behaviors/userstamping.rb
browsercms-3.5.0.rc2 lib/cms/behaviors/userstamping.rb
browsercms-3.5.0.rc1 lib/cms/behaviors/userstamping.rb
browsercms-3.4.2 lib/cms/behaviors/userstamping.rb
browsercms-3.4.2.rc1 lib/cms/behaviors/userstamping.rb
browsercms-3.4.1 lib/cms/behaviors/userstamping.rb
browsercms-3.4.0 lib/cms/behaviors/userstamping.rb
browsercms-3.4.0.rc2 lib/cms/behaviors/userstamping.rb
browsercms-3.4.0.rc1 lib/cms/behaviors/userstamping.rb