Class: KaminariPlugin

Inherits:
SorbetRails::ModelPlugins::Base show all
Defined in:
lib/sorbet-rails/gem_plugins/kaminari_plugin.rb

Overview

typed: strict

Constant Summary

Constants inherited from SorbetRails::ModelPlugins::Base

SorbetRails::ModelPlugins::Base::Parameter

Instance Attribute Summary

Attributes inherited from SorbetRails::ModelPlugins::Base

#available_classes, #model_class

Instance Method Summary collapse

Methods inherited from SorbetRails::ModelPlugins::Base

#initialize

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sorbet-rails/gem_plugins/kaminari_plugin.rb', line 5

def generate(root)
  return unless @model_class.include?(::Kaminari::ActiveRecordModelExtension)

  # Get the configured Kaminari page method name, or fall back to 'page' if necessary.
  page_method = T.unsafe(::Kaminari).config.page_method_name || 'page'

  # https://github.com/kaminari/kaminari/blob/c5186f5d9b7f23299d115408e62047447fd3189d/kaminari-activerecord/lib/kaminari/activerecord/active_record_model_extension.rb#L15
  add_relation_query_method(
    root,
    page_method.to_s,
    parameters: [
      Parameter.new('num', type: 'T.nilable(Integer)', default: 'nil')
    ],
  )

  # https://github.com/kaminari/kaminari/blob/c5186f5d9b7f23299d115408e62047447fd3189d/kaminari-core/lib/kaminari/models/page_scope_methods.rb#L7
  add_relation_query_method(
    root,
    "per",
    parameters: [
      Parameter.new('num', type: 'Integer'),
      Parameter.new('max_per_page', type: 'T.nilable(Integer)', default: 'nil')
    ],
  )

  # https://github.com/kaminari/kaminari/blob/c5186f5d9b7f23299d115408e62047447fd3189d/kaminari-core/lib/kaminari/models/page_scope_methods.rb#L27
  add_relation_query_method(
    root,
    "padding",
    parameters: [
      Parameter.new('num', type: 'Integer')
    ],
  )
end