Class: Athar::Dashboard::FilterSet
- Inherits:
-
Object
- Object
- Athar::Dashboard::FilterSet
- Defined in:
- lib/athar/dashboard/filter_set.rb
Overview
Immutable value object holding the parsed query-param state for a dashboard request. Exposed by DashboardController#index as @filters and consumed by FeedQuery, KpiCalculator, ActorOptions, and the partials.
Constant Summary collapse
- TIMES =
{ "24h" => 24.hours, "7d" => 7.days, "30d" => 30.days, "all" => nil }.freeze
- MODES =
%w[all identity only snapshot].freeze
- KINDS =
%w[all delete truncate].freeze
- DEFAULT_TIME =
"30d"
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#expanded ⇒ Object
readonly
Returns the value of attribute expanded.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
-
.from_params(params) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Summary collapse
- #actor_filter ⇒ Object
-
#initialize(model:, time:, mode:, kind:, actor:, query:, page:, expanded:) ⇒ FilterSet
constructor
rubocop:disable Metrics/ParameterLists.
- #time_cutoff(now = Time.current) ⇒ Object
Constructor Details
#initialize(model:, time:, mode:, kind:, actor:, query:, page:, expanded:) ⇒ FilterSet
rubocop:disable Metrics/ParameterLists
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/athar/dashboard/filter_set.rb', line 29 def initialize(model:, time:, mode:, kind:, actor:, query:, page:, expanded:) # rubocop:disable Metrics/ParameterLists @model = model @time = time @mode = mode @kind = kind @actor = actor @query = query @page = page @expanded = freeze end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def actor @actor end |
#expanded ⇒ Object (readonly)
Returns the value of attribute expanded.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def @expanded end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def kind @kind end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def mode @mode end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def model @model end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def page @page end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def query @query end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
14 15 16 |
# File 'lib/athar/dashboard/filter_set.rb', line 14 def time @time end |
Class Method Details
.from_params(params) ⇒ Object
rubocop:disable Metrics/AbcSize
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/athar/dashboard/filter_set.rb', line 16 def self.from_params(params) # rubocop:disable Metrics/AbcSize new( model: params[:model].presence, time: TIMES.key?(params[:time]) ? params[:time] : DEFAULT_TIME, mode: MODES.include?(params[:mode]) ? params[:mode] : "all", kind: KINDS.include?(params[:kind]) ? params[:kind] : "all", actor: params[:actor].presence || "all", query: params[:q].to_s, page: [params[:page].to_i, 1].max, expanded: params[:expanded].presence ) end |
Instance Method Details
#actor_filter ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/athar/dashboard/filter_set.rb', line 47 def actor_filter return nil if actor == "all" if actor == "anon" { kind: :anon } elsif actor.start_with?("user:") _, type, id = actor.split(":", 3) return nil if id.blank? { kind: :user, type:, id: } elsif actor.start_with?("sys:") { kind: :sys, name: actor.sub("sys:", "") } end end |
#time_cutoff(now = Time.current) ⇒ Object
42 43 44 45 |
# File 'lib/athar/dashboard/filter_set.rb', line 42 def time_cutoff(now = Time.current) delta = TIMES[time] delta ? now - delta : nil end |