Module: VestalVersions::Users::VersionMethods

Defined in:
lib/vestal_versions/users.rb

Overview

Instance methods added to VestalVersions::Version to accomodate incoming user information.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



28
29
30
31
32
33
34
35
# File 'lib/vestal_versions/users.rb', line 28

def self.included(base) # :nodoc:
  base.class_eval do
    belongs_to :user, :polymorphic => true

    alias_method_chain :user, :name
    alias_method_chain :user=, :name
  end
end

Instance Method Details

#user_with_nameObject

Overrides the user method created by the polymorphic belongs_to user association. If the association is absent, defaults to the user_name string column. This allows VestalVersions::Version#user to either return an ActiveRecord::Base object or a string, depending on what is sent to the user_with_name= method.



41
42
43
# File 'lib/vestal_versions/users.rb', line 41

def user_with_name
  user_without_name || user_name
end

#user_with_name=(value) ⇒ Object

Overrides the user= method created by the polymorphic belongs_to user association. Based on the class of the object given, either the user association columns or the user_name string column is populated.



48
49
50
51
52
53
# File 'lib/vestal_versions/users.rb', line 48

def user_with_name=(value)
  case value
    when ActiveRecord::Base then self.user_without_name = value
    else self.user_name = value
  end
end