Module: AbAdmin::Models::AdminComment

Extended by:
ActiveSupport::Concern
Included in:
AdminComment
Defined in:
lib/ab_admin/models/admin_comment.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#decrement_counter_cacheObject


58
59
60
61
# File 'lib/ab_admin/models/admin_comment.rb', line 58

def decrement_counter_cache
  resource.decrement!(:admin_comments_count) if resource_counter_cache?
  true
end

#for_formObject


49
50
51
# File 'lib/ab_admin/models/admin_comment.rb', line 49

def for_form
  {id: id, body: body, user_name: user.try(:name), user_id: user.try(:id), created_at: I18n.l(created_at, format: :long)}
end

#increment_counter_cacheObject


53
54
55
56
# File 'lib/ab_admin/models/admin_comment.rb', line 53

def increment_counter_cache
  resource.increment!(:admin_comments_count) if resource_counter_cache?
  true
end

#resource_counter_cache?Boolean

Returns:

  • (Boolean)

63
64
65
# File 'lib/ab_admin/models/admin_comment.rb', line 63

def resource_counter_cache?
  resource.class.column_names.include?('admin_comments_count')
end

#set_resource_userObject


44
45
46
47
# File 'lib/ab_admin/models/admin_comment.rb', line 44

def set_resource_user
  self.resource_user = resource.try(:user) if resource.respond_to?(:user)
  true
end

#set_user_nameObject


39
40
41
42
# File 'lib/ab_admin/models/admin_comment.rb', line 39

def set_user_name
  self.user_name = user.name.presence || user.email
  true
end