Class: RBI::Tree
- Inherits:
-
Object
- Object
- RBI::Tree
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/rbi_ext/model.rb
Instance Method Summary collapse
- #create_class(name, superclass_name: nil, &block) ⇒ Object
- #create_constant(name, value:) ⇒ Object
- #create_extend(name) ⇒ Object
- #create_include(name) ⇒ Object
- #create_method(name, parameters: [], return_type: "T.untyped", class_method: false, visibility: RBI::Public.new) ⇒ Object
- #create_mixes_in_class_methods(name) ⇒ Object
- #create_module(name, &block) ⇒ Object
- #create_path(constant, &block) ⇒ Object
- #create_type_member(name, value: "type_member") ⇒ Object
Instance Method Details
#create_class(name, superclass_name: nil, &block) ⇒ Object
84 85 86 87 88 |
# File 'lib/tapioca/rbi_ext/model.rb', line 84 def create_class(name, superclass_name: nil, &block) T.cast(create_node(RBI::Class.new(name, superclass_name: superclass_name)), RBI::Scope).tap do |node| block&.call(node) end end |
#create_constant(name, value:) ⇒ Object
91 92 93 |
# File 'lib/tapioca/rbi_ext/model.rb', line 91 def create_constant(name, value:) create_node(RBI::Const.new(name, value)) end |
#create_extend(name) ⇒ Object
101 102 103 |
# File 'lib/tapioca/rbi_ext/model.rb', line 101 def create_extend(name) create_node(RBI::Extend.new(name)) end |
#create_include(name) ⇒ Object
96 97 98 |
# File 'lib/tapioca/rbi_ext/model.rb', line 96 def create_include(name) create_node(RBI::Include.new(name)) end |
#create_method(name, parameters: [], return_type: "T.untyped", class_method: false, visibility: RBI::Public.new) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/tapioca/rbi_ext/model.rb', line 124 def create_method(name, parameters: [], return_type: "T.untyped", class_method: false, visibility: RBI::Public.new) 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, visibility: visibility) 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) ⇒ Object
106 107 108 |
# File 'lib/tapioca/rbi_ext/model.rb', line 106 def create_mixes_in_class_methods(name) create_node(RBI::MixesInClassMethods.new(name)) end |
#create_module(name, &block) ⇒ Object
71 72 73 74 75 |
# File 'lib/tapioca/rbi_ext/model.rb', line 71 def create_module(name, &block) T.cast(create_node(RBI::Module.new(name)), RBI::Scope).tap do |node| block&.call(node) end end |
#create_path(constant, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tapioca/rbi_ext/model.rb', line 55 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") ⇒ Object
111 112 113 |
# File 'lib/tapioca/rbi_ext/model.rb', line 111 def create_type_member(name, value: "type_member") create_node(RBI::TypeMember.new(name, value)) end |