class RBI::Tree
Constants
- SPECIAL_METHOD_NAMES
Public Instance Methods
create_class(name, superclass_name: nil, &block)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 39 def create_class(name, superclass_name: nil, &block) node = create_node(RBI::Class.new(name, superclass_name: superclass_name)) block&.call(T.cast(node, RBI::Scope)) end
create_constant(name, value:)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 45 def create_constant(name, value:) create_node(RBI::Const.new(name, value)) end
create_extend(name)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 55 def create_extend(name) create_node(RBI::Extend.new(name)) end
create_include(name)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 50 def create_include(name) create_node(RBI::Include.new(name)) end
create_method(name, parameters: [], return_type: "T.untyped", class_method: false)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 77 def create_method(name, parameters: [], return_type: "T.untyped", class_method: false) return unless valid_method_name?(name) sig = RBI::Sig.new(return_type: return_type) method = RBI::Method.new(name, sigs: [sig], is_singleton: class_method) parameters.each do |param| method << param.param sig << RBI::SigParam.new(param.param.name, param.type) end self << method end
create_mixes_in_class_methods(name)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 60 def create_mixes_in_class_methods(name) create_node(RBI::MixesInClassMethods.new(name)) end
create_module(name, &block)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 27 def create_module(name, &block) node = create_node(RBI::Module.new(name)) block&.call(T.cast(node, RBI::Scope)) end
create_path(constant, &block)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 11 def create_path(constant, &block) constant_name = Tapioca::Reflection.name_of(constant) raise "given constant does not have a name" unless constant_name instance = ::Module.const_get(constant_name) case instance when ::Class create_class(constant.to_s, &block) when ::Module create_module(constant.to_s, &block) else raise "unexpected type: #{constant_name} is a #{instance.class}" end end
create_type_member(name, value: "type_member")
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 65 def create_type_member(name, value: "type_member") create_node(RBI::TypeMember.new(name, value)) end
Private Instance Methods
create_node(node)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 109 def create_node(node) cached = nodes_cache[node.to_s] return cached if cached nodes_cache[node.to_s] = node self << node node end
nodes_cache()
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 104 def nodes_cache T.must(@nodes_cache ||= T.let({}, T.nilable(T::Hash[String, Node]))) end
valid_method_name?(name)
click to toggle source
# File lib/tapioca/rbi_ext/model.rb, line 98 def valid_method_name?(name) return true if SPECIAL_METHOD_NAMES.include?(name) !!name.match(/^[a-zA-Z_][[:word:]]*[?!=]?$/) end