Sha256: 36e7ccdfeaf02a7927ab7461b0357a38232669b822be54fd00d5608a42ce491a

Contents?: true

Size: 792 Bytes

Versions: 2

Compression:

Stored size: 792 Bytes

Contents

module Ixtlan
  module DataMapper
    module ModifiedBy

      def current_user=( user )
        @_current_user = user
      end

      def current_user
        @_current_user
      end

      def _modified_by
        self.modified_by = @_current_user if dirty? && @_current_user
      end

      def validate_modified_by
        if @_current_user || ! dirty?
          true
        else
          [ false, 'current_user was not set' ]
        end
      end

      module Methods
        def modified_by( *args )
          belongs_to :modified_by, *args

          before :valid?, :_modified_by

          validates_with_method :validate_modified_by
        end
      end

      ::DataMapper::Model.append_inclusions self
      ::DataMapper::Model.append_extensions Methods
    end
  end
end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
ixtlan-datamapper-0.1.0 lib/ixtlan/datamapper/modified_by.rb~
ixtlan-datamapper-0.1.0 lib/ixtlan/datamapper/modified_by.rb