Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop requiring stuff from DSL compilers #1765

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/tapioca/dsl/compilers/aasm.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
require "aasm"
rescue LoadError
return
end
return unless defined?(AASM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was requiring Active Record as well. Does the compiler need ActiveRecord to be defined too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't. I think we were requiring AR to activate the AR support in AASM, but I don't think that's something that is required.

I'll check this again, though.


module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/action_controller_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "action_controller"
rescue LoadError
return
end
return unless defined?(ActionController::Base)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/action_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "action_mailer"
rescue LoadError
return
end
return unless defined?(ActionMailer::Base)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/action_text.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "action_text"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)
paracycle marked this conversation as resolved.
Show resolved Hide resolved

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_job.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_job"
rescue LoadError
return
end
return unless defined?(ActiveJob::Base)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_model_attributes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_model"
rescue LoadError
return
end
return unless defined?(ActiveModel::Attributes)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_model_secure_password.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_model"
rescue LoadError
return
end
return unless defined?(ActiveModel::SecurePassword)

module Tapioca
module Dsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_model"
rescue LoadError
return
end
return unless defined?(ActiveModel::Validations)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_associations.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_constants_helper"

Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_columns.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_column_type_helper"
require "tapioca/dsl/helpers/active_record_constants_helper"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_column_type_helper"
require "tapioca/dsl/helpers/active_record_constants_helper"
Expand Down
8 changes: 1 addition & 7 deletions lib/tapioca/dsl/compilers/active_record_enum.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
# means ActiveRecord is not installed,
# so let's not even define the compiler.
return
end
return unless defined?(ActiveRecord::Base)

module Tapioca
module Dsl
Expand Down
11 changes: 2 additions & 9 deletions lib/tapioca/dsl/compilers/active_record_fixtures.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "rails"
require "active_record"
require "active_record/fixtures"
require "active_support/test_case"
rescue LoadError
return
end
return unless defined?(Rails) && defined?(ActiveSupport::TestCase) && defined?(ActiveRecord::TestFixtures)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could define a defined?(*args) in self?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's possible since defined? is a special language construct and not a method. If we define a defined? method, then arguments to it will be evaluated at the call site, but that's not what we want.


module Tapioca
module Dsl
Expand Down Expand Up @@ -62,7 +55,7 @@ class << self

sig { override.returns(T::Enumerable[Module]) }
def gather_constants
return [] unless Rails.application
return [] unless defined?(Rails.application) && Rails.application
paracycle marked this conversation as resolved.
Show resolved Hide resolved

[ActiveSupport::TestCase]
end
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_constants_helper"

Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_scope.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_constants_helper"

Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_secure_token.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_constants_helper"

Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_record_store.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_record"
rescue LoadError
return
end
return unless defined?(ActiveRecord::Base)

require "tapioca/dsl/helpers/active_record_constants_helper"

Expand Down
8 changes: 1 addition & 7 deletions lib/tapioca/dsl/compilers/active_record_typed_store.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "activerecord-typedstore"
rescue LoadError
# means ActiveRecord::TypedStore is not installed,
# so let's not even define the compiler.
return
end
return unless defined?(ActiveRecord::Base) && defined?(ActiveRecord::TypedStore)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_resource.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_resource"
rescue LoadError
return
end
return unless defined?(ActiveResource::Base)

module Tapioca
module Dsl
Expand Down
7 changes: 1 addition & 6 deletions lib/tapioca/dsl/compilers/active_storage.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_storage"
require "active_storage/reflection"
rescue LoadError
return
end
return unless defined?(ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/active_support_concern.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_support"
rescue LoadError
return
end
return unless defined?(ActiveSupport::Concern)

module Tapioca
module Dsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "active_support"
# The following is needed due to https://github.com/rails/rails/pull/41610
require "active_support/core_ext/module/delegation"
rescue LoadError
return
end
return unless defined?(ActiveSupport::CurrentAttributes)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/config.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "config"
rescue LoadError
return
end
return unless defined?(Config)

module Tapioca
module Dsl
Expand Down
6 changes: 1 addition & 5 deletions lib/tapioca/dsl/compilers/frozen_record.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "frozen_record"
rescue LoadError
return
end
return unless defined?(FrozenRecord::Base)

module Tapioca
module Dsl
Expand Down
8 changes: 2 additions & 6 deletions lib/tapioca/dsl/compilers/graphql_input_object.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# typed: strict
# frozen_string_literal: true

begin
gem("graphql", ">= 1.13")
require "graphql"
rescue LoadError
return
end
return unless defined?(GraphQL::Schema::InputObject)
return unless Gem::Requirement.new(">= 1.13").satisfied_by?(Gem::Version.new(GraphQL::VERSION))

require "tapioca/dsl/helpers/graphql_type_helper"

Expand Down
8 changes: 2 additions & 6 deletions lib/tapioca/dsl/compilers/graphql_mutation.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# typed: strict
# frozen_string_literal: true

begin
gem("graphql", ">= 1.13")
require "graphql"
rescue LoadError
return
end
return unless defined?(GraphQL::Schema::InputObject)
return unless Gem::Requirement.new(">= 1.13").satisfied_by?(Gem::Version.new(GraphQL::VERSION))

require "tapioca/dsl/helpers/graphql_type_helper"

Expand Down
8 changes: 1 addition & 7 deletions lib/tapioca/dsl/compilers/identity_cache.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "identity_cache"
rescue LoadError
# means IdentityCache is not installed,
# so let's not even define the compiler.
return
end
return unless defined?(ActiveRecord::Base) && defined?(IdentityCache::WithoutPrimaryIndex)

require "tapioca/dsl/helpers/active_record_column_type_helper"

Expand Down
8 changes: 1 addition & 7 deletions lib/tapioca/dsl/compilers/json_api_client_resource.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# typed: strict
# frozen_string_literal: true

begin
require "json_api_client"
rescue LoadError
# means JsonApiClient is not installed,
# so let's not even define the compiler.
return
end
return unless defined?(JsonApiClient::Resource)

module Tapioca
module Dsl
Expand Down
Loading
Loading