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

Inherits:
Base
  • Object
show all
Defined in:
lib/decidim/lausanne/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::Lausanne::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.



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

def discardable
  progress + voted
end

#highlighted?(_resource) ⇒ Boolean

No budget resource is highlighted for this workflow.

Returns:

  • (Boolean)


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

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)


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

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

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