123456789_123456789_123456789_123456789_123456789_

Class: RBS::Prototype::Runtime::DataGenerator

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RBS::Prototype::Runtime::ValueObjectBase
Defined in: lib/rbs/prototype/runtime/value_object_generator.rb

Class Method Summary

Instance Method Summary

ValueObjectBase - Inherited

#build_decl,
#build_member_accessors

attr_accessor foo: untyped.

#build_s_members

def self.members: () -> [ :foo, :bar ] def members: () -> [ :foo, :bar ].

Helpers - Included

#const_name, #const_name!,
#only_name

Returns the exact name & not compactly declared name.

#to_type_name, #untyped

Constructor Details

This class inherits a constructor from RBS::Prototype::Runtime::ValueObjectBase

Class Method Details

.generatable?(target) ⇒ Boolean

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/value_object_generator.rb', line 212

def self.generatable?(target)
  return false unless RUBY_VERSION >= '3.2'
  return false unless target < Data
  # Avoid direct inherited class like `class Option < Data`
  return false unless target.respond_to?(:members)

  true
end

Instance Method Details

#add_decl_members(decl) (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/value_object_generator.rb', line 227

def add_decl_members(decl)
  decl.members.concat build_s_new
  decl.members.concat build_s_members
  decl.members.concat build_member_accessors(AST::Members::AttrReader)
end

#build_s_new (private)

def self.new: (untyped foo, untyped bar) -> instance

| (foo: untyped, bar: untyped) -> instance
[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/value_object_generator.rb', line 235

def build_s_new
  [:new, :[]].map do |name|
    new_overloads = []

    new_overloads << AST::Members::MethodDefinition::Overload.new(
      annotations: [],
      method_type: MethodType.new(
        type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
          required_positionals: @target_class.members.map { |m| Types::Function::Param.new(name: m, type: untyped) },
        ),
        type_params: [],
        block: nil,
        location: nil,
      )
    )
    new_overloads << AST::Members::MethodDefinition::Overload.new(
      annotations: [],
      method_type: MethodType.new(
        type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
          required_keywords: @target_class.members.to_h { |m| [m, Types::Function::Param.new(name: nil, type: untyped)] },
        ),
        type_params: [],
        block: nil,
        location: nil,
      )
    )

    AST::Members::MethodDefinition.new(
      name: name,
      overloads: new_overloads,
      kind: :singleton,
      location: nil,
      comment: nil,
      annotations: [],
      overloading: false,
      visibility: nil
    )
  end
end

#build_super_class (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/value_object_generator.rb', line 223

def build_super_class
  AST::Declarations::Class::Super.new(name: TypeName("::Data"), args: [], location: nil)
end