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) ⇒ 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
83 84 85 86 |
# File 'lib/tapioca/rbi_ext/model.rb', line 83 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:) ⇒ Object
89 90 91 |
# File 'lib/tapioca/rbi_ext/model.rb', line 89 def create_constant(name, value:) create_node(RBI::Const.new(name, value)) end |
#create_extend(name) ⇒ Object
99 100 101 |
# File 'lib/tapioca/rbi_ext/model.rb', line 99 def create_extend(name) create_node(RBI::Extend.new(name)) end |
#create_include(name) ⇒ Object
94 95 96 |
# File 'lib/tapioca/rbi_ext/model.rb', line 94 def create_include(name) create_node(RBI::Include.new(name)) end |
#create_method(name, parameters: [], return_type: "T.untyped", class_method: false) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/tapioca/rbi_ext/model.rb', line 121 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) ⇒ Object
104 105 106 |
# File 'lib/tapioca/rbi_ext/model.rb', line 104 def create_mixes_in_class_methods(name) create_node(RBI::MixesInClassMethods.new(name)) end |
#create_module(name, &block) ⇒ Object
71 72 73 74 |
# File 'lib/tapioca/rbi_ext/model.rb', line 71 def create_module(name, &block) node = create_node(RBI::Module.new(name)) block&.call(T.cast(node, RBI::Scope)) 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
109 110 111 |
# File 'lib/tapioca/rbi_ext/model.rb', line 109 def create_type_member(name, value: "type_member") create_node(RBI::TypeMember.new(name, value)) end |