let Zeitwerk autoload the `lib/` directory

this also allows the UseCase classes to be hot reloaded in dev 🎉

- remove use_case requires (except for the exporter as Zeitwerk
  doesn't know about the subclasses)
- move version.rb to lib/retrospring so that Zeitwerk knows where
  to find Retrospring::Version
This commit is contained in:
Georg Gadinger 2022-12-29 06:49:15 +01:00 committed by Andreas Nedbal
parent 447d1f7e6d
commit 9413d23a02
37 changed files with 10 additions and 66 deletions

View File

@ -1,5 +1,5 @@
require 'use_case/user/ban'
require 'use_case/user/unban'
# frozen_string_literal: true
require 'errors'
class Ajax::ModerationController < AjaxController

View File

@ -1,9 +1,6 @@
# frozen_string_literal: true
require "errors"
require "use_case/question/create"
require "use_case/question/create_followers"
require "use_case/question/destroy"
class Ajax::QuestionController < AjaxController
def destroy

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/relationship/create"
require "use_case/relationship/destroy"
require "errors"
class Ajax::RelationshipController < AjaxController

View File

@ -8,8 +8,6 @@ start = Time.now
Bundler.require(*Rails.groups)
puts 'processing time of bundler require: ' + "#{(Time.now - start).round(3).to_s.ljust(5, '0')}s".light_green
require_relative "../lib/version"
module Justask
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
@ -17,7 +15,11 @@ module Justask
# -- all .rb files in that directory are automatically loaded.
config.load_defaults 6.0
config.autoload_paths += %W["#{config.root}/app/validators"]
# add `lib/` to the autoload paths so zeitwerk can find e.g. our `UseCase`s
# without an explicit `require`, and also take care of hot reloading the code
# (really useful in development!)
config.autoload_paths << config.root.join("lib")
config.eager_load_paths << config.root.join("lib")
# Use Sidekiq for background jobs
config.active_job.queue_adapter = :sidekiq

View File

@ -9,7 +9,7 @@ namespace :version do
now = Time.now.utc
today_ymd = %i[year month day].map { now.public_send(_1) }
version_path = Rails.root.join("lib/version.rb")
version_path = Rails.root.join("lib/retrospring/version.rb")
version_contents = File.read(version_path)
patch_contents = lambda do |key, val|
@ -35,7 +35,7 @@ namespace :version do
desc "Commit and tag a new release"
task commit: :environment do
version_path = Rails.root.join("lib/version.rb")
version_path = Rails.root.join("lib/retrospring/version.rb")
puts "Committing version"
sh %(git commit -m 'Bump version to #{Retrospring::Version}' -- #{version_path.to_s.inspect})

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Answers < UseCase::DataExport::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Appendables < UseCase::DataExport::Base

View File

@ -2,8 +2,6 @@
require "json"
require "use_case/base"
module UseCase
module DataExport
class Base < UseCase::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Comments < UseCase::DataExport::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class MuteRules < UseCase::DataExport::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Questions < UseCase::DataExport::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Relationships < UseCase::DataExport::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/data_export/base"
module UseCase
module DataExport
class Theme < UseCase::DataExport::Base

View File

@ -2,8 +2,6 @@
require "httparty"
require "use_case/data_export/base"
module UseCase
module DataExport
class User < UseCase::DataExport::Base

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
require "errors"
module UseCase

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
module UseCase
module Question
class CreateFollowers < UseCase::Base

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
require "errors"
module UseCase

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
require "errors"
module UseCase

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
require "errors"
module UseCase

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "use_case/base"
module UseCase
module User
class Ban < UseCase::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'use_case/base'
module UseCase
module User
class Unban < UseCase::Base

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require "version"
RSpec.describe Retrospring::Version do
before(:each) do
allow(Retrospring::Version).to receive(:year) { 1984 }

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/answers"
describe UseCase::DataExport::Answers, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/appendables"
describe UseCase::DataExport::Appendables, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/comments"
describe UseCase::DataExport::Comments, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/mute_rules"
describe UseCase::DataExport::MuteRules, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/questions"
describe UseCase::DataExport::Questions, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/relationships"
describe UseCase::DataExport::Relationships, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/theme"
describe UseCase::DataExport::Theme, :data_export do
include ActiveSupport::Testing::TimeHelpers

View File

@ -2,8 +2,6 @@
require "rails_helper"
require "use_case/data_export/user"
describe UseCase::DataExport::User, :data_export do
let(:user_params) do
{

View File

@ -2,7 +2,6 @@
require "rails_helper"
require "errors"
require "use_case/question/create_followers"
describe UseCase::Question::CreateFollowers do
subject do

View File

@ -2,7 +2,6 @@
require "rails_helper"
require "errors"
require "use_case/question/create"
describe UseCase::Question::Create do
subject do

View File

@ -2,7 +2,6 @@
require "rails_helper"
require "errors"
require "use_case/question/destroy"
describe UseCase::Question::Destroy do
subject do

View File

@ -2,7 +2,6 @@
require "rails_helper"
require "use_case/relationship/create"
require "errors"
describe UseCase::Relationship::Create do

View File

@ -2,7 +2,6 @@
require "rails_helper"
require "use_case/relationship/destroy"
require "errors"
describe UseCase::Relationship::Destroy do

View File

@ -2,8 +2,6 @@
raise ArgumentError.new("This file should only be required in the 'test' environment! Current environment: #{Rails.env}") unless Rails.env.test?
require "use_case/data_export/base"
# an example exporter to be used for the tests of `Exporter`
#
# this only returning basic files, nothing user-specific. each exporter should be tested individually.