Class: Yoda::Model::Environment::NamespaceMembers

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/model/environment/namespace_members.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accessor:, environment:) ⇒ NamespaceMembers

Returns a new instance of NamespaceMembers.

Parameters:



15
16
17
18
# File 'lib/yoda/model/environment/namespace_members.rb', line 15

def initialize(accessor:, environment:)
  @accessor = accessor
  @environment = environment
end

Instance Attribute Details

#accessorAccessorInterface (readonly)

Returns:



8
9
10
# File 'lib/yoda/model/environment/namespace_members.rb', line 8

def accessor
  @accessor
end

#environmentEnvironment (readonly)

Returns:



11
12
13
# File 'lib/yoda/model/environment/namespace_members.rb', line 11

def environment
  @environment
end

Instance Method Details

#select_constant_paths(name) ⇒ Array<Symbol>

Parameters:

  • name (String, Symbol)

Returns:

  • (Array<Symbol>)


44
45
46
47
48
# File 'lib/yoda/model/environment/namespace_members.rb', line 44

def select_constant_paths(name, **)
  # TODO: Search RBS
  stored_consts = stored_constant_members&.select(name) || []
  stored_consts.map(&:path)
end

#select_constant_type(name) ⇒ RBS::Types::t

Parameters:

  • name (String, Symbol)

Returns:

  • (RBS::Types::t)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/yoda/model/environment/namespace_members.rb', line 52

def select_constant_type(name, **)
  paths = select_constant_paths(name)

  types = paths.flat_map do |path|
    name = accessor.environment.resolve_rbs_type_name(path)
    name && RBS::Types::ClassSingleton.new(
      name: name,
      location: nil,
    )
  end.compact

  if types.empty?
    RBS::Types::Bases::Any.new(location: nil)
  else
    RBS::Types::Union.new(types: types, location: nil)
  end
end

#select_method(name, visibility:) ⇒ Enumerator<FunctionSignatures::Base>

Parameters:

  • name (String, Symbol, Regexp)
  • visibility (Array<:private, :public, :protected>)

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yoda/model/environment/namespace_members.rb', line 23

def select_method(name, visibility:)
  rbs_method_signatures = begin
    method_defs = filter_rbs_methods(name, visibility: visibility)
    method_defs.flat_map do |method_def|
      method_def.defs.map do |type_def|
        FunctionSignatures::RbsMethod.new(
          rbs_definition: accessor.rbs_definition,
          rbs_method_definition: method_def,
          rbs_method_typedef: type_def,
        )
      end
    end
  end

  stored_signatures = stored_method_members&.select_signature(name, visibility: visibility) || []

  (rbs_method_signatures + stored_signatures).map { |sig| sig.wrap(environment) }
end