Skip to content

Commit

Permalink
use super from parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobperia committed Oct 13, 2023
1 parent f08bf03 commit 16e0fb1
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/components/matey/active_users_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Matey::ActiveUsersComponent < Matey::ApplicationComponent
def initialize(events:, time_window: 1.week, color_scheme: "neutral")
validate_arguments(records: events, time_window: time_window)
super(records: events, time_window: time_window)

@current_period = events.where(time: time_window.ago..Time.current).pluck(:user_id).uniq.count
previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).uniq.count
Expand Down
11 changes: 6 additions & 5 deletions app/components/matey/application_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ class Matey::ApplicationComponent < ViewComponent::Base
include ActiveModel::Validations
include ColorSchemeHelper

def before_render
validate!
end

def validate_arguments(records:, time_window:)
def initialize(records:, time_window:)
super
raise ArgumentError unless records.is_a?(ActiveRecord::Relation)
raise ArgumentError unless time_window.is_a?(Integer)
end

def before_render
validate!
end
end
2 changes: 1 addition & 1 deletion app/components/matey/browser_os_breakdown_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Matey::BrowserOsBreakdownComponent < Matey::ApplicationComponent
def initialize(visits:, time_window:, color_scheme: "neutral")
validate_arguments(records: visits, time_window: time_window)
super(records: visits, time_window: time_window)

visits_in_time_window = visits.where(started_at: time_window.ago..)
@visits_in_time_window = visits_in_time_window.count
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/daily_active_users_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Matey::DailyActiveUsersComponent < Matey::ApplicationComponent
def initialize(visits:, time_window:, color_scheme: "neutral")
validate_arguments(records: visits, time_window: time_window)
super(records: visits, time_window: time_window)

@visits = visits
@time_window = time_window
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/new_activity_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Matey::NewActivityComponent < Matey::ApplicationComponent
def initialize(events:, time_window: 1.week, color_scheme: "neutral")
validate_arguments(records: events, time_window: time_window)
super(records: events, time_window: time_window)

@current_period = events.where(time: time_window.ago..Time.current).count
previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).count
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/new_users_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Matey::NewUsersComponent < Matey::ApplicationComponent
def initialize(users:, time_window: 1.week, color_scheme: "neutral")
validate_arguments(records: users, time_window: time_window)
super(records: users, time_window: time_window)

@current_period = users.where(created_at: time_window.ago..Time.current).count
previous_period = users.where(created_at: (2 * time_window).ago..time_window.ago).count
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/top_events_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Matey::TopEventsComponent < Matey::ApplicationComponent
def initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral")
validate_arguments(records: events, time_window: time_window)
super(records: events, time_window: time_window)

@events = events.where(time: time_window.ago..Time.current).limit(limit).order("count(name) DESC").group(:name).count
@time_window = time_window
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/top_visited_pages_table_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Matey::TopVisitedPagesTableComponent < Matey::ApplicationComponent
def initialize(events:, time_window: 1.week, limit: 10, color_scheme: "neutral")
validate_arguments(records: events, time_window: time_window)
super(records: events, time_window: time_window)

# Group events by controller (:name) and action. Aggregate number of unique user actions
@user_count_by_event = events.where(started_at: time_window.ago..).pluck(:landing_page).tally
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/user_engagement_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Matey::UserEngagementComponent < Matey::ApplicationComponent
def initialize(events:, user_id:, time_window: 1.week, limit: 10, color_scheme: "neutral")
validate_arguments(records: events, time_window: time_window)
super(records: events, time_window: time_window)

@events_for_user = events.where_props(user_id: user_id).where(time: time_window.ago..Time.current).group(:name).count
@count_by_event = @events_for_user.sort_by { |event, count| count }.last(limit).reverse
Expand Down
2 changes: 1 addition & 1 deletion app/components/matey/visits_by_day_of_week_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Matey::VisitsByDayOfWeekComponent < Matey::ApplicationComponent
def initialize(visits:, time_window: 1.month, exclude_days: [], color_scheme: "neutral")
validate_arguments(records: visits, time_window: time_window)
super(records: visits, time_window: time_window)

@visits = visits
@time_window = time_window
Expand Down

0 comments on commit 16e0fb1

Please sign in to comment.