Skip to content

Commit

Permalink
use keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobperia committed Oct 13, 2023
1 parent b7eee6d commit f08bf03
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 10 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(events, time_window)
validate_arguments(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
2 changes: 1 addition & 1 deletion app/components/matey/application_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def before_render
validate!
end

def validate_arguments(records, time_window)
def validate_arguments(records:, time_window:)
raise ArgumentError unless records.is_a?(ActiveRecord::Relation)
raise ArgumentError unless time_window.is_a?(Integer)
end
Expand Down
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(visits, time_window)
validate_arguments(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(visits, time_window)
validate_arguments(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(events, time_window)
validate_arguments(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(users, time_window)
validate_arguments(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(events, time_window)
validate_arguments(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(events, time_window)
validate_arguments(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(events, time_window)
validate_arguments(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(visits, time_window)
validate_arguments(records: visits, time_window: time_window)

@visits = visits
@time_window = time_window
Expand Down

0 comments on commit f08bf03

Please sign in to comment.