Class: Decidim::Debates::Debate
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Debates::Debate
- Includes:
- Authorable, Comments::Commentable, Followable, HasCategory, HasComponent, HasReference, Loggable, Reportable, Resourceable, ScopableComponent, Traceable
- Defined in:
- app/models/decidim/debates/debate.rb
Overview
The data store for a Debate in the Decidim::Debates component. It stores a title, description and any other useful information to render a custom debate.
Class Method Summary collapse
Instance Method Summary collapse
-
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
-
#ama? ⇒ Boolean
Public: Calculates whether the current debate is an AMA-styled one or not.
-
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
-
#commentable_type ⇒ Object
Public: Identifies the commentable type in the API.
-
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
-
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
-
#notifiable?(_context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method.
-
#official? ⇒ Boolean
Public: Checks whether the debate is official or not.
-
#open? ⇒ Boolean
Public: Checks if the debate is open or not.
-
#open_ama? ⇒ Boolean
Public: Checks whether the debate is an AMA-styled one and is open.
-
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
-
#users_to_notify_on_comment_created ⇒ Object
Public: Override Commentable concern method ‘users_to_notify_on_comment_created`.
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
25 26 27 |
# File 'app/models/decidim/debates/debate.rb', line 25 def self.log_presenter_class_for(_log) Decidim::Debates::AdminLog::DebatePresenter end |
Instance Method Details
#accepts_new_comments? ⇒ Boolean
Public: Overrides the ‘accepts_new_comments?` Commentable concern method.
71 72 73 74 |
# File 'app/models/decidim/debates/debate.rb', line 71 def accepts_new_comments? return false unless open? commentable? && !comments_blocked? end |
#ama? ⇒ Boolean
Public: Calculates whether the current debate is an AMA-styled one or not. AMA-styled debates are those that have a start and end time set, and comments are only open during that timelapse. AMA stands for Ask Me Anything, a type of debate inspired by Reddit.
Returns a Boolean.
47 48 49 |
# File 'app/models/decidim/debates/debate.rb', line 47 def ama? start_time.present? && end_time.present? end |
#commentable? ⇒ Boolean
Public: Overrides the ‘commentable?` Commentable concern method.
66 67 68 |
# File 'app/models/decidim/debates/debate.rb', line 66 def commentable? component.settings.comments_enabled? end |
#commentable_type ⇒ Object
Public: Identifies the commentable type in the API.
87 88 89 |
# File 'app/models/decidim/debates/debate.rb', line 87 def commentable_type self.class.name end |
#comments_have_alignment? ⇒ Boolean
Public: Overrides the ‘comments_have_alignment?` Commentable concern method.
77 78 79 |
# File 'app/models/decidim/debates/debate.rb', line 77 def comments_have_alignment? true end |
#comments_have_votes? ⇒ Boolean
Public: Overrides the ‘comments_have_votes?` Commentable concern method.
82 83 84 |
# File 'app/models/decidim/debates/debate.rb', line 82 def comments_have_votes? true end |
#notifiable?(_context) ⇒ Boolean
Public: Overrides the ‘notifiable?` Notifiable concern method.
92 93 94 |
# File 'app/models/decidim/debates/debate.rb', line 92 def notifiable?(_context) false end |
#official? ⇒ Boolean
Public: Checks whether the debate is official or not.
Returns a boolean.
32 33 34 |
# File 'app/models/decidim/debates/debate.rb', line 32 def official? .blank? end |
#open? ⇒ Boolean
Public: Checks if the debate is open or not.
Returns a boolean.
61 62 63 |
# File 'app/models/decidim/debates/debate.rb', line 61 def open? (ama? && open_ama?) || !ama? end |
#open_ama? ⇒ Boolean
Public: Checks whether the debate is an AMA-styled one and is open.
Returns a boolean.
54 55 56 |
# File 'app/models/decidim/debates/debate.rb', line 54 def open_ama? ama? && Time.current.between?(start_time, end_time) end |
#reported_content_url ⇒ Object
Public: Overrides the ‘reported_content_url` Reportable concern method.
37 38 39 |
# File 'app/models/decidim/debates/debate.rb', line 37 def reported_content_url ResourceLocatorPresenter.new(self).url end |
#users_to_notify_on_comment_created ⇒ Object
Public: Override Commentable concern method ‘users_to_notify_on_comment_created`
97 98 99 100 |
# File 'app/models/decidim/debates/debate.rb', line 97 def users_to_notify_on_comment_created return Decidim::User.where(id: followers).or(Decidim::User.where(id: component.participatory_space.admins)).distinct if official? followers end |