Class: Decidim::Initiatives::InitiativesPromoted

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/initiatives/initiatives_promoted.rb

Overview

Class uses to retrieve initiatives promoted by the given user

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ InitiativesPromoted

Initializes the class.

user: Decidim::User



19
20
21
# File 'app/queries/decidim/initiatives/initiatives_promoted.rb', line 19

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'app/queries/decidim/initiatives/initiatives_promoted.rb', line 7

def user
  @user
end

Class Method Details

.by(user) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

user - Decidim::User



12
13
14
# File 'app/queries/decidim/initiatives/initiatives_promoted.rb', line 12

def self.by(user)
  new(user).query
end

Instance Method Details

#queryObject

Retrieves the initiatives promoted by the given user.



24
25
26
27
28
29
# File 'app/queries/decidim/initiatives/initiatives_promoted.rb', line 24

def query
  Initiative
    .joins(:committee_members)
    .where("decidim_initiatives_committee_members.state = 2")
    .where(decidim_initiatives_committee_members: { decidim_users_id: user.id })
end