Class: Thredded::PostView

Inherits:
Object
  • Object
show all
Defined in:
app/view_models/thredded/post_view.rb

Overview

A view model for PostCommon.

Instance Method Summary collapse

Constructor Details

#initialize(post, policy) ⇒ PostView

Returns a new instance of PostView.

Parameters:



19
20
21
22
# File 'app/view_models/thredded/post_view.rb', line 19

def initialize(post, policy)
  @post   = post
  @policy = policy
end

Instance Method Details

#cache_keyObject

rubocop:disable Metrics/CyclomaticComplexity



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/view_models/thredded/post_view.rb', line 49

def cache_key
  moderation_state = unless @post.private_topic_post?
                       if @post.pending_moderation? && !Thredded.content_visible_while_pending_moderation
                         'p'
                       elsif @post.blocked?
                         '-'
                       end
                     end
  [
    I18n.locale,
    @post,
    @post.user,
    moderation_state || '+',
    [
      can_update?,
      can_destroy?
    ].map { |p| p ? '+' : '-' } * ''
  ]
end

#can_destroy?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/view_models/thredded/post_view.rb', line 28

def can_destroy?
  @can_destroy ||= @policy.destroy?
end

#can_moderate?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/view_models/thredded/post_view.rb', line 32

def can_moderate?
  @can_moderate ||= @policy.moderate?
end

#can_update?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/view_models/thredded/post_view.rb', line 24

def can_update?
  @can_update ||= @policy.update?
end

#destroy_pathObject



40
41
42
# File 'app/view_models/thredded/post_view.rb', line 40

def destroy_path
  Thredded::UrlsHelper.delete_post_path(@post)
end

#edit_pathObject



36
37
38
# File 'app/view_models/thredded/post_view.rb', line 36

def edit_path
  Thredded::UrlsHelper.edit_post_path(@post)
end


44
45
46
# File 'app/view_models/thredded/post_view.rb', line 44

def permalink_path
  Thredded::UrlsHelper.post_permalink_path(@post.id)
end