Class: Decidim::Sortitions::Sortition

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::CommentableWithComponent, FilterableResource, HasCategory, HasComponent, HasReference, Loggable, Randomable, Resourceable, Traceable, TranslatableResource
Defined in:
decidim-sortitions/app/models/decidim/sortitions/sortition.rb

Overview

Model that encapsulates the parameters of a sortion

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object


35
36
37
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 35

def self.log_presenter_class_for(_log)
  Decidim::Sortitions::AdminLog::SortitionPresenter
end

.ransackable_scopes(_auth_object = nil) ⇒ Object


83
84
85
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 83

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_state, :with_category]
end

Instance Method Details

#accepts_new_comments?Boolean

Public: Overrides the `accepts_new_comments?` Commentable concern method.

Returns:

  • (Boolean)

60
61
62
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 60

def accepts_new_comments?
  commentable?
end

#allow_resource_permissions?Boolean

Public: Overrides the `allow_resource_permissions?` Resourceable concern method.

Returns:

  • (Boolean)

75
76
77
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 75

def allow_resource_permissions?
  true
end

#cancelled?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 55

def cancelled?
  cancelled_on.present?
end

#comments_have_alignment?Boolean

Public: Overrides the `comments_have_alignment?` Commentable concern method.

Returns:

  • (Boolean)

65
66
67
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 65

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the `comments_have_votes?` Commentable concern method.

Returns:

  • (Boolean)

70
71
72
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 70

def comments_have_votes?
  true
end

#proposalsObject


39
40
41
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 39

def proposals
  Decidim::Proposals::Proposal.where(id: selected_proposals)
end

#seedObject


51
52
53
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 51

def seed
  request_timestamp.to_i * dice
end

#similar_countObject


43
44
45
46
47
48
49
# File 'decidim-sortitions/app/models/decidim/sortitions/sortition.rb', line 43

def similar_count
  Sortition.where(component: component)
           .where(decidim_proposals_component: decidim_proposals_component)
           .with_category(category&.id)
           .where(target_items: target_items)
           .count
end