Class: Decidim::MetricManage
- Inherits:
-
Object
- Object
- Decidim::MetricManage
show all
- Defined in:
- decidim-core/app/queries/decidim/metric_manage.rb
Overview
This class search for objects related to Metrics, and creates a new registry within its own parameters
Direct Known Subclasses
Accountability::Metrics::ResultsMetricManage, Assemblies::Metrics::AssembliesMetricManage, Comments::Metrics::CommentsMetricManage, Debates::Metrics::DebatesMetricManage, Decidim::Meetings::Metrics::MeetingsMetricManage, Decidim::Metrics::BlockedUsersMetricManage, Decidim::Metrics::FollowersMetricManage, Decidim::Metrics::ParticipantsMetricManage, Decidim::Metrics::ReportedUsersMetricManage, Decidim::Metrics::UserReportsMetricManage, Decidim::Metrics::UsersMetricManage, ParticipatoryProcesses::Metrics::ParticipatoryProcessesMetricManage, Proposals::Metrics::EndorsementsMetricManage, Proposals::Metrics::ProposalsMetricManage, Proposals::Metrics::VotesMetricManage, Surveys::Metrics::AnswersMetricManage
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(day_string, organization) ⇒ MetricManage
Returns a new instance of MetricManage.
11
12
13
14
15
16
17
18
|
# File 'decidim-core/app/queries/decidim/metric_manage.rb', line 11
def initialize(day_string, organization)
@day = day_string.present? ? Date.parse(day_string) : Time.zone.yesterday
raise ArgumentError, "[ERROR] Malformed `day` argument. Format must be `YYYY-MM-DD` and in the past" if @day > Time.zone.today
@day ||= Time.zone.yesterday
@organization = organization
@metric_name = metric_name
end
|
Class Method Details
.for(day_string, organization) ⇒ Object
7
8
9
|
# File 'decidim-core/app/queries/decidim/metric_manage.rb', line 7
def self.for(day_string, organization)
new(day_string, organization)
end
|
Instance Method Details
#metric_name ⇒ Object
20
21
22
|
# File 'decidim-core/app/queries/decidim/metric_manage.rb', line 20
def metric_name
""
end
|
#save ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'decidim-core/app/queries/decidim/metric_manage.rb', line 28
def save
return @registry if @registry
return if cumulative.zero? && %w(blocked_users reported_users user_reports).exclude?(@metric_name)
@registry = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name, organization: @organization)
@registry.assign_attributes(cumulative:, quantity:)
@registry.save!
@registry
end
|
#valid? ⇒ Boolean
24
25
26
|
# File 'decidim-core/app/queries/decidim/metric_manage.rb', line 24
def valid?
@day.present?
end
|