Class: Decidim::Budgets::Workflows::One

Inherits:
Base
  • Object
show all
Defined in:
lib/decidim/budgets/workflows/one.rb

Overview

This Workflow allows users to vote in any budget, but only in one.

Instance Attribute Summary

Attributes inherited from Base

#budgets_component, #user

Instance Method Summary collapse

Methods inherited from Base

#allowed, #budgets, #highlighted, #initialize, #limit_reached?, #progress, #progress?, #single, #single?, #status, #voted, #voted?

Constructor Details

This class inherits a constructor from Decidim::Budgets::Workflows::Base

Instance Method Details

#discardableObject

Public: Returns a list of budgets where the user can discard their order to vote in another.

Returns Array.



27
28
29
# File 'lib/decidim/budgets/workflows/one.rb', line 27

def discardable
  progress + voted
end

#highlighted?(_resource) ⇒ Boolean

No budget resource is highlighted for this workflow.

Returns:

  • (Boolean)


9
10
11
# File 'lib/decidim/budgets/workflows/one.rb', line 9

def highlighted?(_resource)
  false
end

#vote_allowed?(resource, consider_progress: true) ⇒ Boolean

Users can vote in any budget with this workflow, but only in one.

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/decidim/budgets/workflows/one.rb', line 14

def vote_allowed?(resource, consider_progress: true)
  return false if voted.any?

  if consider_progress
    progress?(resource) || progress.none?
  else
    true
  end
end