Skip to content

Commit

Permalink
chore: format/lint with standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirojose committed Oct 4, 2024
1 parent 81f6ef3 commit f998a96
Show file tree
Hide file tree
Showing 47 changed files with 144 additions and 149 deletions.
2 changes: 1 addition & 1 deletion apps/govquests-api/govquests/authentication/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"

eval_gemfile "../../infra/Gemfile.test"
gem "infra", path: "../../infra"
gem "infra", path: "../../infra"
2 changes: 1 addition & 1 deletion apps/govquests-api/govquests/questing/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Questing
class Test < Infra::InMemoryTest
def before_setup
super()
super
Configuration.new.call(event_store, command_bus)
end

Expand Down
1 change: 0 additions & 1 deletion apps/govquests-api/infra/lib/infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "arkency/command_bus"
require "dry-struct"
require "dry-types"
require "aggregate_root"
require "active_support/notifications"
require "minitest"
require "ruby_event_store/transformations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def initialize(event_store, notifications = ActiveSupport::Notifications)
)
end

def with_aggregate(aggregate_class, aggregate_id, &block)
def with_aggregate(aggregate_class, aggregate_id, &)
@repository.with_aggregate(
aggregate_class.new(aggregate_id),
stream_name(aggregate_class, aggregate_id),
&block
&
)
end

Expand Down
2 changes: 1 addition & 1 deletion apps/govquests-api/infra/lib/infra/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(event_id: SecureRandom.uuid, metadata: nil, data: {})
end

def self.included(klass)
klass.extend WithSchema::ClassMethods
klass.extend WithSchema::ClassMethods
klass.include WithSchema::Constructor
end
end
Expand Down
10 changes: 4 additions & 6 deletions apps/govquests-api/infra/lib/infra/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ def call(event_name, event_data_keys, command, command_data_keys)
->(event) do
@command_bus.call(
command.new(
Hash[
command_data_keys.zip(
event_data_keys.map { |key| event.data.fetch(key) }
)
]
command_data_keys.zip(
event_data_keys.map { |key| event.data.fetch(key) }
).to_h
)
)
end,
to: [event_name]
)
end
end
end
end
16 changes: 8 additions & 8 deletions apps/govquests-api/infra/lib/infra/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def self.with(event_store:, command_bus:)

def self.included(klass)
klass.include TestPlumbing.with(
event_store: -> { EventStore.in_memory },
command_bus: -> { CommandBus.new }
)
event_store: -> { EventStore.in_memory },
command_bus: -> { CommandBus.new }
)
end

module TestMethods
Expand All @@ -27,19 +27,19 @@ def arrange(*commands)
end

def act(command)
command_bus.(command)
command_bus.call(command)
end
alias run_command act
alias_method :run_command, :act

def assert_events(stream_name, *expected_events)
scope = event_store.read.stream(stream_name)
before = scope.last
yield
actual_events =
before.nil? ? scope.to_a : scope.from(before.event_id).to_a
to_compare = ->(ev) { { type: ev.event_type, data: ev.data } }
to_compare = ->(ev) { {type: ev.event_type, data: ev.data} }
assert_equal expected_events.map(&to_compare),
actual_events.map(&to_compare)
actual_events.map(&to_compare)
end

def assert_events_contain(stream_name, *expected_events)
Expand All @@ -48,7 +48,7 @@ def assert_events_contain(stream_name, *expected_events)
yield
actual_events =
before.nil? ? scope.to_a : scope.from(before.event_id).to_a
to_compare = ->(ev) { { type: ev.event_type, data: ev.data } }
to_compare = ->(ev) { {type: ev.event_type, data: ev.data} }
expected_events.map(&to_compare).each do |expected|
assert_includes(actual_events.map(&to_compare), expected)
end
Expand Down
1 change: 0 additions & 1 deletion apps/govquests-api/infra/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
require "mutant/minitest/coverage"

require_relative "../lib/infra"

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ def start
action = ActionTracking::ActionReadModel.find_by(action_id: params[:action_id])
if action
token = generate_completion_token(action.action_id)
render json: { token: token, expires_at: 30.minutes.from_now }
render json: {token: token, expires_at: 30.minutes.from_now}
else
render json: { error: "Action not found" }, status: :not_found
render json: {error: "Action not found"}, status: :not_found
end
end

Expand All @@ -18,9 +18,9 @@ def complete
completion_data: params[:completion_data]
)
Rails.configuration.command_bus.call(command)
render json: { message: "Action completed successfully" }
render json: {message: "Action completed successfully"}
else
render json: { error: "Invalid completion attempt" }, status: :unprocessable_entity
render json: {error: "Invalid completion attempt"}, status: :unprocessable_entity
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show
rewards: quest.rewards
}
else
render json: { error: "Quest not found" }, status: :not_found
render json: {error: "Quest not found"}, status: :not_found
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ActionLogReadModel < ApplicationRecord

class ReadModelConfiguration
def call(event_store)
event_store.subscribe(OnActionCreated, to: [ ActionTracking::ActionCreated ])
event_store.subscribe(OnActionExecuted, to: [ ActionTracking::ActionExecuted ])
event_store.subscribe(OnActionCreated, to: [ActionTracking::ActionCreated])
event_store.subscribe(OnActionExecuted, to: [ActionTracking::ActionExecuted])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def call(event)
user = UserReadModel.find_or_initialize_by(user_id: user_id)
user.email = email
user.user_type = user_type
user.wallets = [ { wallet_address: wallet_address, chain_id: chain_id } ]
user.wallets = [{wallet_address: wallet_address, chain_id: chain_id}]
user.save!
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class UserReadModel < ApplicationRecord
self.table_name = "users"

validates :user_id, presence: true, uniqueness: true
validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :user_type, presence: true, inclusion: { in: %w[delegate non_delegate] }
validates :email, uniqueness: true, format: {with: URI::MailTo::EMAIL_REGEXP}
validates :user_type, presence: true, inclusion: {in: %w[delegate non_delegate]}
end

class SessionReadModel < ApplicationRecord
Expand All @@ -18,8 +18,8 @@ class SessionReadModel < ApplicationRecord

class ReadModelConfiguration
def call(event_store)
event_store.subscribe(OnUserRegistered.new, to: [ Authentication::UserRegistered ])
event_store.subscribe(OnUserLoggedIn.new, to: [ Authentication::UserLoggedIn ])
event_store.subscribe(OnUserRegistered.new, to: [Authentication::UserRegistered])
event_store.subscribe(OnUserLoggedIn.new, to: [Authentication::UserLoggedIn])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def call(event)
if badges.include?(badge)
Rails.logger.info "Badge '#{badge}' already exists for GameProfile #{profile_id}"
else
game_profile.update(badges: badges + [ badge ])
game_profile.update(badges: badges + [badge])
Rails.logger.info "Added badge '#{badge}' to GameProfile #{profile_id}"
end
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class LeaderboardEntryReadModel < ApplicationRecord

class ReadModelConfiguration
def call(event_store)
event_store.subscribe(OnTierAchieved, to: [ Gamification::TierAchieved ])
event_store.subscribe(OnTrackCompleted, to: [ Gamification::TrackCompleted ])
event_store.subscribe(OnStreakMaintained, to: [ Gamification::StreakMaintained ])
event_store.subscribe(OnBadgeEarned, to: [ Gamification::BadgeEarned ])
event_store.subscribe(OnLeaderboardUpdated, to: [ Gamification::LeaderboardUpdated ])
event_store.subscribe(OnTierAchieved, to: [Gamification::TierAchieved])
event_store.subscribe(OnTrackCompleted, to: [Gamification::TrackCompleted])
event_store.subscribe(OnStreakMaintained, to: [Gamification::StreakMaintained])
event_store.subscribe(OnBadgeEarned, to: [Gamification::BadgeEarned])
event_store.subscribe(OnLeaderboardUpdated, to: [Gamification::LeaderboardUpdated])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def call(event)
opened_at = event.data.fetch(:opened_at)

notification = NotificationReadModel.find_by(notification_id: notification_id)
notification.update(opened_at: opened_at, status: "opened") if notification
notification&.update(opened_at: opened_at, status: "opened")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def call(event)
received_at = event.data.fetch(:received_at)

notification = NotificationReadModel.find_by(notification_id: notification_id)
notification.update(received_at: received_at, status: "received") if notification
notification&.update(received_at: received_at, status: "received")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def call(event)
scheduled_time = event.data.fetch(:scheduled_time)

notification = NotificationReadModel.find_by(notification_id: notification_id)
notification.update(scheduled_time: scheduled_time, status: "scheduled") if notification
notification&.update(scheduled_time: scheduled_time, status: "scheduled")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def call(event)
template_id = event.data.fetch(:template_id)

template = NotificationTemplateReadModel.find_by(template_id: template_id)
template.destroy if template
template&.destroy
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class NotificationReadModel < ApplicationRecord
validates :template_id, presence: true
validates :user_id, presence: true
validates :channel, presence: true
validates :priority, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 6 }
validates :status, presence: true, inclusion: { in: %w[created scheduled sent received opened] }
validates :priority, presence: true, numericality: {only_integer: true, greater_than: 0, less_than: 6}
validates :status, presence: true, inclusion: {in: %w[created scheduled sent received opened]}
end

class NotificationTemplateReadModel < ApplicationRecord
Expand All @@ -16,22 +16,22 @@ class NotificationTemplateReadModel < ApplicationRecord
validates :template_id, presence: true, uniqueness: true
validates :name, presence: true, uniqueness: true
validates :content, presence: true
validates :template_type, presence: true, inclusion: { in: [ "email", "SMS", "push" ] }
validates :template_type, presence: true, inclusion: {in: ["email", "SMS", "push"]}
end

class ReadModelConfiguration
def call(event_store)
# Notification Events
event_store.subscribe(OnNotificationCreated, to: [ Notifications::NotificationCreated ])
event_store.subscribe(OnNotificationScheduled, to: [ Notifications::NotificationScheduled ])
event_store.subscribe(OnNotificationSent, to: [ Notifications::NotificationSent ])
event_store.subscribe(OnNotificationReceived, to: [ Notifications::NotificationReceived ])
event_store.subscribe(OnNotificationOpened, to: [ Notifications::NotificationOpened ])
event_store.subscribe(OnNotificationCreated, to: [Notifications::NotificationCreated])
event_store.subscribe(OnNotificationScheduled, to: [Notifications::NotificationScheduled])
event_store.subscribe(OnNotificationSent, to: [Notifications::NotificationSent])
event_store.subscribe(OnNotificationReceived, to: [Notifications::NotificationReceived])
event_store.subscribe(OnNotificationOpened, to: [Notifications::NotificationOpened])

# NotificationTemplate Events
event_store.subscribe(OnTemplateCreated, to: [ Notifications::NotificationTemplateCreated ])
event_store.subscribe(OnTemplateUpdated, to: [ Notifications::NotificationTemplateUpdated ])
event_store.subscribe(OnTemplateDeleted, to: [ Notifications::NotificationTemplateDeleted ])
event_store.subscribe(OnTemplateCreated, to: [Notifications::NotificationTemplateCreated])
event_store.subscribe(OnTemplateUpdated, to: [Notifications::NotificationTemplateUpdated])
event_store.subscribe(OnTemplateDeleted, to: [Notifications::NotificationTemplateDeleted])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def call(event)
action = ActionTracking::ActionReadModel.find_by(action_id: event.data[:action_id])

if quest && action
quest_action = QuestActionReadModel.create!(
QuestActionReadModel.create!(
quest: quest,
action: action,
position: event.data[:position]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class UserQuest < ApplicationRecord

class ReadModelConfiguration
def call(event_store)
event_store.subscribe(OnQuestCreated, to: [ Questing::QuestCreated ])
event_store.subscribe(OnActionAssociatedWithQuest, to: [ Questing::ActionAssociatedWithQuest ])
event_store.subscribe(OnQuestCreated, to: [Questing::QuestCreated])
event_store.subscribe(OnActionAssociatedWithQuest, to: [Questing::ActionAssociatedWithQuest])
# event_store.subscribe(OnUserStartedQuest, to: [Questing::UserStartedQuest])
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def image_url

class ReadModelConfiguration
def call(event_store)
event_store.subscribe(OnRewardCreated, to: [ Rewarding::RewardCreated ])
event_store.subscribe(OnRewardIssued, to: [ Rewarding::RewardIssued ])
event_store.subscribe(OnRewardClaimed, to: [ Rewarding::RewardClaimed ])
event_store.subscribe(OnRewardExpired, to: [ Rewarding::RewardExpired ])
event_store.subscribe(OnRewardInventoryDepleted, to: [ Rewarding::RewardInventoryDepleted ])
event_store.subscribe(OnRewardCreated, to: [Rewarding::RewardCreated])
event_store.subscribe(OnRewardIssued, to: [Rewarding::RewardIssued])
event_store.subscribe(OnRewardClaimed, to: [Rewarding::RewardClaimed])
event_store.subscribe(OnRewardExpired, to: [Rewarding::RewardExpired])
event_store.subscribe(OnRewardInventoryDepleted, to: [Rewarding::RewardInventoryDepleted])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def initialize(event_store, active_record_name, id_column)
end

def subscribe_create(creation_event)
@event_store.subscribe(create_handler(creation_event), to: [ creation_event ])
@event_store.subscribe(create_handler(creation_event), to: [creation_event])
end

def subscribe_copy(event, sequence_of_keys, column = Array(sequence_of_keys).join("_"))
@event_store.subscribe(copy_handler(event, sequence_of_keys, column), to: [ event ])
@event_store.subscribe(copy_handler(event, sequence_of_keys, column), to: [event])
end

private
Expand Down
4 changes: 2 additions & 2 deletions apps/govquests-api/rails_app/bin/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ m = Module.new do
if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o
bundler_version = $1
update_index = i
end
Expand All @@ -56,7 +56,7 @@ m = Module.new do
def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o
Regexp.last_match(1)
end

Expand Down
4 changes: 2 additions & 2 deletions apps/govquests-api/rails_app/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)

def system!(*args)
system(*args, exception: true)
def system!(*)
system(*, exception: true)
end

FileUtils.chdir APP_ROOT do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Enable/disable Action Controller caching. By default Action Controller caching is disabled.
# Run rails dev:cache to toggle Action Controller caching.
if Rails.root.join("tmp/caching-dev.txt").exist?
config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" }
config.public_file_server.headers = {"cache-control" => "public, max-age=#{2.days.to_i}"}
else
config.action_controller.perform_caching = false
end
Expand All @@ -36,7 +36,7 @@
config.action_mailer.perform_caching = false

# Set localhost to be used by links generated in mailer templates.
config.action_mailer.default_url_options = { host: "localhost", port: 3001 }
config.action_mailer.default_url_options = {host: "localhost", port: 3001}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand Down
Loading

0 comments on commit f998a96

Please sign in to comment.