Class: SorbetRails::ModelPlugins::Base

Inherits:
Parlour::Plugin
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
SorbetRails::ModelUtils
Defined in:
lib/sorbet-rails/model_plugins/base.rb

Constant Summary collapse

Parameter =

convenient rename

::Parlour::RbiGenerator::Parameter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SorbetRails::ModelUtils

#add_relation_query_method, #exists_class_method?, #exists_instance_method?, #habtm_class?, #model_assoc_proxy_class_name, #model_assoc_relation_class_name, #model_class_name, #model_module_name, #model_query_methods_returning_assoc_relation_module_name, #model_query_methods_returning_relation_module_name, #model_relation_class_name, #model_relation_type_alias, #model_relation_type_class_name

Methods included from SorbetRails::ModelColumnUtils

#active_record_type_to_sorbet_type, #attribute_has_unconditional_presence_validation?, #nilable_column?, #time_zone_aware_column?, #type_for_column_def

Constructor Details

#initialize(model_class, available_classes) ⇒ Base

Returns a new instance of Base.


28
29
30
31
# File 'lib/sorbet-rails/model_plugins/base.rb', line 28

def initialize(model_class, available_classes)
  @model_class = T.let(model_class, T.class_of(ActiveRecord::Base))
  @available_classes = T.let(available_classes, T::Set[String])
end

Instance Attribute Details

#available_classesObject (readonly)

Returns the value of attribute available_classes


19
20
21
# File 'lib/sorbet-rails/model_plugins/base.rb', line 19

def available_classes
  @available_classes
end

#model_classObject (readonly)

Returns the value of attribute model_class


16
17
18
# File 'lib/sorbet-rails/model_plugins/base.rb', line 16

def model_class
  @model_class
end

Instance Method Details

#serialization_coder_for_column(column_name) ⇒ Object


34
35
36
37
38
39
# File 'lib/sorbet-rails/model_plugins/base.rb', line 34

def serialization_coder_for_column(column_name)
  column_type = @model_class.type_for_attribute(column_name)
  return unless column_type.is_a?(ActiveRecord::Type::Serialized)

  column_type.coder.try(:object_class) || Object
end