Class: Tapioca::Compilers::Dsl::MixedInClassAttributes

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/compilers/dsl/mixed_in_class_attributes.rb

Overview

`Tapioca::Compilers::Dsl::MixedInClassAttributes` generates RBI files for modules that dynamically use `class_attribute` on classes.

For example, given the following concern

~~~rb module Taggeable

extend ActiveSupport::Concern

included do
  class_attribute :tag
end

end ~~~

this generator will produce the RBI file `taggeable.rbi` with the following content:

~~~rbi # typed: strong

module Taggeable

include GeneratedInstanceMethods

mixes_in_class_methods GeneratedClassMethods

module GeneratedClassMethods
  def tag; end
  def tag=(value); end
  def tag?; end
end

module GeneratedInstanceMethods
  def tag; end
  def tag=(value); end
  def tag?; end
end

end ~~~

Constant Summary

Constants included from Reflection

Reflection::ANCESTORS_METHOD, Reflection::CLASS_METHOD, Reflection::CONSTANTS_METHOD, Reflection::EQUAL_METHOD, Reflection::METHOD_METHOD, Reflection::NAME_METHOD, Reflection::OBJECT_ID_METHOD, Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Reflection::SINGLETON_CLASS_METHOD, Reflection::SUPERCLASS_METHOD

Instance Attribute Summary

Attributes inherited from Base

#errors, #processable_constants

Instance Method Summary collapse

Methods inherited from Base

#add_error, #handles?, #initialize

Methods included from Reflection

#ancestors_of, #are_equal?, #class_of, #constants_of, #descendants_of, #inherited_ancestors_of, #method_of, #name_of, #name_of_type, #object_id_of, #private_instance_methods_of, #protected_instance_methods_of, #public_instance_methods_of, #qualified_name_of, #signature_of, #singleton_class_of, #superclass_of

Constructor Details

This class inherits a constructor from Tapioca::Compilers::Dsl::Base

Instance Method Details

#decorate(root, constant) ⇒ Object


55
56
57
58
59
60
61
62
# File 'lib/tapioca/compilers/dsl/mixed_in_class_attributes.rb', line 55

def decorate(root, constant)
  mixin_compiler = DynamicMixinCompiler.new(constant)
  return if mixin_compiler.empty_attributes?

  root.create_path(constant) do |mod|
    mixin_compiler.compile_class_attributes(mod)
  end
end

#gather_constantsObject


65
66
67
68
69
70
# File 'lib/tapioca/compilers/dsl/mixed_in_class_attributes.rb', line 65

def gather_constants
  # Select all non-anonymous modules that have overridden Module.included
  all_modules.select do |mod|
    !mod.is_a?(Class) && name_of(mod) && Tapioca::Reflection.method_of(mod, :included).owner != Module
  end
end