Class: SorbetRails::ModelPlugins::ActiveRecordNamedScope
- Inherits:
-
Base
- Object
- Parlour::Plugin
- Base
- SorbetRails::ModelPlugins::ActiveRecordNamedScope
- Defined in:
- lib/sorbet-rails/model_plugins/active_record_named_scope.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#available_classes, #model_class
Instance Method Summary collapse
Methods inherited from Base
Methods included from SorbetRails::ModelUtils
#add_relation_query_method, #exists_class_method?, #exists_instance_method?, #model_assoc_proxy_class_name, #model_assoc_relation_class_name, #model_class, #model_class_name, #model_module_name, #model_relation_class_name, #model_relation_type_alias, #model_relation_type_class_name
Constructor Details
This class inherits a constructor from SorbetRails::ModelPlugins::Base
Instance Method Details
#generate(root) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sorbet-rails/model_plugins/active_record_named_scope.rb', line 7 def generate(root) model_class_rbi = root.create_class(self.model_class_name) @model_class.methods.sort.each do |method_name| next unless SorbetRails::Utils.valid_method_name?(method_name.to_s) method_obj = @model_class.method(method_name) next unless method_obj.present? && method_obj.source_location.present? # we detect sscopes defined in a model by 2 criteria: # - they don't have an owner name # - they are defined in 'activerecord/lib/active_record/scoping/named.rb' # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/scoping/named.rb next unless method_obj.owner.name == nil source_file = method_obj.source_location[0] next unless source_file.include?("lib/active_record/scoping/named.rb") add_relation_query_method( root, method_name.to_s, parameters: [ Parameter.new("*args", type: "T.untyped"), ], ) end end |