Class Comment
In: app/models/comment.rb
Parent: ActiveRecord::Base

Methods

Included Modules

KotobaModel

Constants

MAXIMUM_LENGTH = 80

Public Class methods

[Source]

   # File app/models/comment.rb, line 5
5:   def self.overview
6:     KotobaModel.overview(self)
7:   end

Public Instance methods

[Source]

    # File app/models/comment.rb, line 32
32:   def language_id=(id)
33:     current_user_language
34:     super
35:   end

[Source]

    # File app/models/comment.rb, line 19
19:   def to_label
20:     if comment and comment.length > MAXIMUM_LENGTH
21:       comment[0..(MAXIMUM_LENGTH-1)] +  '...'
22:     else
23:       comment
24:     end
25:   end

[Source]

    # File app/models/comment.rb, line 27
27:   def user_id=(id)
28:     current_user_as_owner
29:     super
30:   end

Protected Instance methods

[Source]

    # File app/models/comment.rb, line 56
56:   def authorized_for_create?
57:     return user == current_user || Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_USER)
58:   end

[Source]

    # File app/models/comment.rb, line 64
64:   def authorized_for_destroy?
65:     return user == current_user || Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ADMIN)
66:   end

[Source]

    # File app/models/comment.rb, line 68
68:   def authorized_for_read?
69:     return Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_USER)
70:   end

[Source]

    # File app/models/comment.rb, line 60
60:   def authorized_for_update?
61:     return user == current_user || Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ADMIN)
62:   end

[Source]

    # File app/models/comment.rb, line 49
49:   def current_user_as_owner
50:     unless @user_id
51:       @user_id = current_user.id
52:       write_attribute('user_id', current_user.id)
53:     end
54:   end

[Source]

    # File app/models/comment.rb, line 39
39:   def current_user_language
40:     unless @language_id
41:       user_native_language = Language.find_by_iso_639_code(current_user.language_native)
42:       if user_native_language
43:         @language_id = user_native_language.id
44:         write_attribute('language_id', user_native_language.id)
45:       end
46:     end
47:   end

[Validate]