Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/tapioca/commands/abstract_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def existing_rbi_filenames(requested_constants, path: @outpath)
filenames.to_set
end

#: (Array[String] constant_names, ?ignore_missing: bool) -> Array[T::Module[top]]
#: (Array[String] constant_names, ?ignore_missing: bool) -> Array[Module[top]]
def constantize(constant_names, ignore_missing: false)
constant_map = constant_names.to_h do |name|
[name, Object.const_get(name)]
Expand Down
18 changes: 9 additions & 9 deletions lib/tapioca/dsl/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Tapioca
module Dsl
# @abstract
#: [ConstantType < T::Module[top]]
#: [ConstantType < Module[top]]
class Compiler
include RBIHelper
include Runtime::Reflection
Expand All @@ -19,24 +19,24 @@ class Compiler
#: Hash[String, untyped]
attr_reader :options

@@requested_constants = [] #: Array[T::Module[top]] # rubocop:disable Style/ClassVars
@@requested_constants = [] #: Array[Module[top]] # rubocop:disable Style/ClassVars

class << self
#: (T::Module[top] constant) -> bool
#: (Module[top] constant) -> bool
def handles?(constant)
processable_constants.include?(constant)
end

# @abstract
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants = raise NotImplementedError, "Abstract method called"

#: -> Set[T::Module[top]]
#: -> Set[Module[top]]
def processable_constants
@processable_constants ||= T::Set[T::Module[T.anything]].new.compare_by_identity.merge(gather_constants) #: Set[T::Module[top]]?
@processable_constants ||= T::Set[T::Module[T.anything]].new.compare_by_identity.merge(gather_constants) #: Set[Module[top]]?
end

#: (Array[T::Module[top]] constants) -> void
#: (Array[Module[top]] constants) -> void
def requested_constants=(constants)
@@requested_constants = constants # rubocop:disable Style/ClassVars
end
Expand Down Expand Up @@ -69,13 +69,13 @@ def all_classes
@all_classes ||= all_modules.grep(Class).freeze #: Enumerable[Class[top]]?
end

#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def all_modules
@all_modules ||= if @@requested_constants.any?
@@requested_constants.grep(Module)
else
ObjectSpace.each_object(Module).to_a
end.freeze #: Enumerable[T::Module[top]]?
end.freeze #: Enumerable[Module[top]]?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/aasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
T.cast(ObjectSpace.each_object(::AASM::ClassMethods), T::Enumerable[T::Module[T.anything]])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/action_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActionController::Base).select(&:name).select do |klass|
klass.const_defined?(:HelperMethods, false)
Expand Down Expand Up @@ -148,7 +148,7 @@ def create_unknown_proxy_method(helper_methods, method_name)
)
end

#: (T::Module[top] mod) -> Array[String]
#: (Module[top] mod) -> Array[String]
def gather_includes(mod)
mod.ancestors
.reject { |ancestor| ancestor.is_a?(Class) || ancestor == mod || name_of(ancestor).nil? }
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActionMailer::Base).reject(&:abstract?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/action_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def action_text_associations(constant)
end

# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base)
.reject(&:abstract_class?)
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def perform_later_parameters(parameters, constant_name)

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveJob::Base)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_model_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
all_classes.grep(::ActiveModel::Attributes::ClassMethods)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
# In some versions of Rails 8.1, `ActiveModel::SecurePassword` uses `Numeric#minutes`
# which isn't explicitly required in the gem, and it might not be loaded already.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Compilers
class ActiveModelValidationsConfirmation < Compiler
class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
# Collect all the classes that include ActiveModel::Validations
all_classes.select { |c| ActiveModel::Validations > c }
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
return [] unless defined?(Rails.application) && Rails.application

Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
ActiveRecord::Base.descendants.reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_secure_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_typed_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).select do |klass|
klass.include?(ActiveRecord::TypedStore::Behavior)
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveResource::Base)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Compilers
# def photo=(attachable); end
# end
# ~~~
#: [ConstantType = (T::Module[top] & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
#: [ConstantType = (Module[top] & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
class ActiveStorage < Compiler
# @override
#: -> void
Expand All @@ -64,7 +64,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base)
.reject(&:abstract_class?)
Expand Down
12 changes: 6 additions & 6 deletions lib/tapioca/dsl/compilers/active_support_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Compilers
# mixes_in_class_methods(::Foo::ClassMethods)
# end
# ~~~
#: [ConstantType = T::Module[top]]
#: [ConstantType = Module[top]]
class ActiveSupportConcern < Compiler
# @override
#: -> void
Expand All @@ -61,7 +61,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
all_modules.select do |mod|
name_of(mod) && # i.e. not anonymous
Expand All @@ -72,23 +72,23 @@ def gather_constants
end

# Returns true when `mod` includes other concerns
#: (T::Module[top] mod) -> bool
#: (Module[top] mod) -> bool
def has_dependencies?(mod) = dependencies_of(mod).any?

#: (T::Module[top] concern) -> Array[T::Module[top]]
#: (Module[top] concern) -> Array[Module[top]]
def dependencies_of(concern)
concern.instance_variable_get(:@_dependencies) || []
end
end

private

#: (T::Module[top] concern) -> Array[T::Module[top]]
#: (Module[top] concern) -> Array[Module[top]]
def dependencies_of(concern)
self.class.dependencies_of(concern)
end

#: (?T::Module[top] concern) -> Array[T::Module[top]]
#: (?Module[top] concern) -> Array[Module[top]]
def linearized_dependencies(concern = constant)
# Grab all the dependencies of the concern
dependencies = dependencies_of(concern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveSupport::CurrentAttributes)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def decorate

class << self
# @override
#: -> T::Enumerable[T::Module[top]]
#: -> T::Enumerable[Module[top]]
def gather_constants
return [] unless defined?(Rails.application) && Rails.application

Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_support_time_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
[::Time]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Compilers
# def github=(value); end
# end
# ```
#: [ConstantType = T::Module[top]]
#: [ConstantType = Module[top]]
class Config < Compiler
CONFIG_OPTIONS_SUFFIX = "ConfigOptions"

Expand Down Expand Up @@ -92,7 +92,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
name = ::Config.const_name
return [] unless Object.const_defined?(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/frozen_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::FrozenRecord::Base).reject(&:abstract_class?)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/graphql_input_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def method_defined_by_graphql?(method_name)

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
all_classes.select { |c| GraphQL::Schema::InputObject > c }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/graphql_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def argument_type(argument, constant)

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
all_classes.select { |c| GraphQL::Schema::Mutation > c && GraphQL::Schema::RelayClassicMutation != c }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/identity_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module Compilers
# ~~~
#: [ConstantType = singleton(::ActiveRecord::Base)]
class IdentityCache < Compiler
COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((T::Module[top] | String) type) -> String
COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((Module[top] | String) type) -> String

# @override
#: -> void
Expand Down Expand Up @@ -91,7 +91,7 @@ def decorate

class << self
# @override
#: -> Enumerable[T::Module[top]]
#: -> Enumerable[Module[top]]
def gather_constants
descendants_of(::ActiveRecord::Base).select do |klass|
::IdentityCache::WithoutPrimaryIndex > klass
Expand Down
Loading
Loading